dart_frog_auth 1.2.0 dart_frog_auth: ^1.2.0 copied to clipboard
Header authentication based middlewares for Dart Frog. Built by Very Good Ventures.
Example #
Use basicAuthentication
to add basic authentication to your routes:
// routes/admin/_middleware.dart
import 'package:dart_frog/dart_frog.dart';
import 'package:dart_frog_auth/dart_frog_auth.dart';
import 'package:blog/user.dart';
Handler middleware(Handler handler) {
final userRepository = ...;
return handler
.use(requestLogger())
.use(
basicAuthentication<User>(
userFromCredentials: userRepository.fetchFromCredentials,
),
);
}
User bearerAuthentication
to add bearer token authentication to your routes:
// routes/admin/_middleware.dart
import 'package:dart_frog/dart_frog.dart';
import 'package:dart_frog_auth/dart_frog_auth.dart';
import 'package:blog/user.dart';
Handler middleware(Handler handler) {
final userRepository = ...;
return handler
.use(requestLogger())
.use(
bearerAuthentication<User>(
userFromToken: userRepository.fetchFromAccessToken,
),
);
}