ApiKeyGuard class

API Key Guard.

Static API key authentication.

await Auth.login({'api_key': 'sk_live_xxx'}, user);
Inheritance

Constructors

ApiKeyGuard({String tokenKey = 'api_key', String? userEndpoint, Authenticatable userFactory(Map<String, dynamic>)?})

Properties

cachedToken String?
Cached token for sync access.
no setterinherited
guest bool
Check if user is a guest (not authenticated).
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
refreshEndpoint String?
API endpoint to refresh access token.
finalinherited
refreshTokenKey String?
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateNotifier ValueNotifier<int>
Auth state notifier.
finalinherited
tokenKey String
Vault keys.
finalinherited
userCacheKey String
finalinherited
userEndpoint String?
API endpoint to fetch user data.
finalinherited
userFactory Authenticatable Function(Map<String, dynamic>)?
Factory to create user from API response.
finalinherited

Methods

cacheUser(Authenticatable user) Future<void>
Cache user data to Vault.
inherited
check() bool
Check if user is authenticated.
inherited
clearTokens() Future<void>
Clear all tokens.
inherited
clearUserCache() Future<void>
Clear cached user.
inherited
extractUserData(Map<String, dynamic>? data) Map<String, dynamic>?
Extract user data from API response.
inherited
getRefreshToken() Future<String?>
Get refresh token.
inherited
getToken() Future<String?>
Get the stored token.
inherited
hasToken() Future<bool>
Check if a token exists in storage.
inherited
id() → dynamic
Get the authenticated user's ID.
inherited
loadCachedUser() Future<Authenticatable?>
Load user from cache.
inherited
loadTokenToCache() Future<void>
Load token into cache.
inherited
login(Map<String, dynamic> data, Authenticatable user) Future<void>
Login with data and set the authenticated user.
override
logout() Future<void>
End the session.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refreshToken() Future<bool>
Refresh the access token using the refresh token.
inherited
restore() Future<void>
Restore session from storage.
inherited
setUser(Authenticatable user) → void
Set the user directly.
inherited
storeToken(String token, [String? refreshToken]) Future<void>
Store token (and optional refresh token).
inherited
toString() String
A string representation of this object.
inherited
user<T extends Model>() → T?
Get the authenticated user.
inherited

Operators

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