dart_frog_auth 1.1.0 copy "dart_frog_auth: ^1.1.0" to clipboard
dart_frog_auth: ^1.1.0 copied to clipboard

Header authentication based middlewares for Dart Frog. Built by Very Good Ventures.

example/README.md

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,
        ),
      );
}