Strategies
Just like in Passport, strategies implement authentication via a specific provider. To create your own strategy, you need to implement the AuthStrategy class.
All strategies must implement authenticate(req, res, [opts]).

authenticate

This method should only have three possible results.
Possibility #1: Return true
This signifies that whatever authentication process you performed was completed successfully, and that it did not produce any result that needs to be serialized.
Possibility #2: Return false
This represents an authentication failure, and will throw a 401 Not Authenticated error.
Possibility #3: Return something else entirely
This signifies that although the user was successfully authenticated, the authenticated user needs to be serialized into another format for the entire authentication flow to be considered complete.
For example, you usually need to save a user's ID after authentication.
1
import 'package:angel3_auth/angel3_auth.dart';
2
โ€‹
3
class MyStrategy implements AuthStrategy {
4
@override
5
authenticate(req, res, [opts]) async {
6
final user =
7
await login(req.body['username'], req.body['password']);
8
โ€‹
9
return user != null ? user : false;
10
}
11
}
Copied!
Last modified 5mo ago
Copy link
Contents
authenticate