dox_auth 2.0.0-alpha2 copy "dox_auth: ^2.0.0-alpha2" to clipboard
dox_auth: ^2.0.0-alpha2 copied to clipboard

Authentication package for dox framework with jsonwebtoken(jwt) driver.

example/example.md

  1. Create auth config
import 'package:dox_auth/dox_auth.dart';
import 'package:dox_core/dox_core.dart';
import 'package:dox/models/user/user.model.dart';

class AuthConfig extends AuthConfigInterface {
  @override
  String get defaultGuard => 'web';

  @override
  Map<String, Guard> get guards => <String, Guard>{
        'web': Guard(
          driver: JwtDriver(
            secret: SecretKey(Env.get('APP_KEY')),
          ),
          provider: Provider(
            model: () => User(),
          ),
        ),
      };
}
  1. Modify bin/server.dart to add auth config
Dox dox = Dox();
await dox.initialize(config);
dox.setAuthConfig(AuthConfig());
  1. Attempt Login
Map<String, dynamic> credentials = req.only(<String>['email', 'password']);

Auth auth = Auth();
String? token = await auth.attempt(credentials);
User? user = auth.user<User>();
  1. Register doxAuthMiddleware in route
 Route.get('/auth/user', <dynamic>[doxAuthMiddleware, authController.user]);
  1. Verify Logged In or Fetch User information
Future<dynamic> fetchUser(DoxRequest req) async {
  Auth? auth = req.auth<Auth>();
  if (auth?.isLoggedIn() == true) {
    return auth?.user();
  }
  throw UnAuthorizedException();
}
1
likes
0
pub points
0%
popularity

Publisher

verified publisherdartondox.dev

Authentication package for dox framework with jsonwebtoken(jwt) driver.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bcrypt, dart_jsonwebtoken, dox_annotation, dox_query_builder

More

Packages that depend on dox_auth