authenticated method

Future<bool> authenticated()

Checks if the user is currently authenticated (access token is valid).

This method verifies whether there is a valid access token stored locally and whether that token has not expired. It does not make a network request to verify the token with the server.

Returns

A Future that resolves to true if the user is authenticated with a valid token, false otherwise

Example

final isAuthenticated = await calljmp.users.auth.email.authenticated();
if (isAuthenticated) {
  print('User is already signed in');
} else {
  print('User needs to authenticate');
}

Implementation

Future<bool> authenticated() async {
  final token = await CalljmpStore.instance.get(CalljmpStoreKey.accessToken);
  if (token != null) {
    final result = AccessToken.tryParse(token);
    if (result.data != null) {
      return result.data!.isValid;
    }
  }
  return false;
}