authenticate method
Future<AngelAuthResult>
authenticate({
- String? type,
- dynamic credentials,
- String authEndpoint = '/auth',
- @deprecated String reviveEndpoint = '/auth/token',
override
Authenticates against the server.
This is designed with package:angel_auth in mind.
The type is appended to the authEndpoint, ex. local becomes /auth/local.
The given credentials are sent to server as-is; the request body is sent as JSON.
Implementation
@override
Future<AngelAuthResult> authenticate(
{String? type,
credentials,
String authEndpoint = '/auth',
@deprecated String reviveEndpoint = '/auth/token'}) async {
if (type == null || type == 'token') {
if (!window.localStorage.containsKey('token')) {
throw Exception(
'Cannot revive token from localStorage - there is none.');
}
var token = json.decode(window.localStorage['token']!);
credentials ??= {'token': token};
}
final result = await super.authenticate(
type: type, credentials: credentials, authEndpoint: authEndpoint);
window.localStorage['token'] = json.encode(authToken = result.token);
window.localStorage['user'] = json.encode(result.data);
return result;
}