loginWithJWT method
if the jwt is valid and allowed then it will return user id else null
Implementation
Future<String?> loginWithJWT(String jwt) async {
// verify the jwt isn't manipulated
var res = JWT.tryVerify(jwt, authDbProvider.app.authSettings.jwtSecretKey);
if (res == null) {
return null;
}
// get the data from the jwt
JWTPayloadModel model = JWTPayloadModel.fromJson(res.payload);
// check for the jwt in the allowed jwt tokens and active
bool jwtIsActive = await authDbProvider.checkIfJwtIsActive(model);
if (!jwtIsActive) {
throw PasswordChangedException();
}
// check for the user id if it is a valid user
AuthModel? authModel = await authDbProvider.getUserByEmail(model.email);
if (authModel == null) {
return null;
}
// then allow the user to continue
return authModel.id;
}