ApiGuard class

API authentication guard

This guard handles authentication for API requests. It uses token-based authentication and is suitable for stateless API authentication where tokens are sent in headers.

Inheritance

Constructors

ApiGuard({required AuthConfig config, required AuthDriver driver, required String providerKey, AuthRepository? repository, PasswordVerifier? passwordVerifier})
Creates an API guard
ApiGuard.create(String providerKey, AuthDriver driver)
Factory constructor for easy instantiation
factory
ApiGuard.fromConfig(AuthConfig config, String guardName, [String? providerKey])
Factory constructor with config
factory

Properties

config AuthConfig
Authentication configuration
finalinherited
driver AuthDriver
The authentication driver
finalinherited
hashCode int
The hash code for this object.
no setterinherited
passwordVerifier PasswordVerifier
Password verifier
finalinherited
providerKey String
The provider key
finalinherited
repository AuthRepository
Authentication repository
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

attempt(Map<String, dynamic> credentials) Future<AuthResponse>
Attempts to authenticate a user with credentials
inherited
check(String token) Future<bool>
Checks if a token is valid
inherited
login(Authenticatable user) Future<AuthResponse>
Authenticates a user directly (without password check)
inherited
logout(String token) Future<void>
Logs out a user by invalidating their token
inherited
logoutAll(dynamic token) Future<void>
Logs out the user from all devices (invalidates all tokens)
inherited
logoutOthers(dynamic userId, String currentToken) Future<void>
Logs out the user from other devices (invalidates all tokens except current)
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh(String refreshToken) Future<AuthResponse>
Refreshes an access token
inherited
toString() String
A string representation of this object.
inherited
user(String token) Future<Authenticatable>
Verifies an authentication token
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited