mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 19:34:54 +00:00
getting spaces and rooms from api {null checks}
This commit is contained in:
@ -10,9 +10,26 @@ class Token {
|
||||
final String accessToken;
|
||||
final String refreshToken;
|
||||
|
||||
//{
|
||||
// "email": "test@test.com",
|
||||
// "userId": 3,
|
||||
// "uuid": "563e22d2-cb30-46d3-8c48-fa7d762342f0",
|
||||
// "sessionId": "f76aa067-c915-4921-b04d-9fbc71c4965a",
|
||||
// "iat": 1710137435,
|
||||
// "exp": 1710137735
|
||||
// }
|
||||
|
||||
final String sessionId;
|
||||
|
||||
final int iat;
|
||||
final int exp;
|
||||
|
||||
Token.emptyConstructor()
|
||||
: accessToken = '',
|
||||
refreshToken = '';
|
||||
refreshToken = '',
|
||||
sessionId = '',
|
||||
iat = 0,
|
||||
exp = 0;
|
||||
|
||||
bool get accessTokenIsNotEmpty => accessToken.isNotEmpty;
|
||||
|
||||
@ -23,9 +40,16 @@ class Token {
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
this.sessionId,
|
||||
this.iat,
|
||||
this.exp,
|
||||
);
|
||||
|
||||
Token.refreshToken(this.refreshToken) : accessToken = '';
|
||||
Token.refreshToken(this.refreshToken)
|
||||
: accessToken = '',
|
||||
sessionId = '',
|
||||
iat = 0,
|
||||
exp = 0;
|
||||
|
||||
factory Token.fromJson(Map<String, dynamic> json) {
|
||||
//save token to secure storage
|
||||
@ -34,15 +58,16 @@ class Token {
|
||||
key: loginAccessTokenKey, value: json[loginAccessTokenKey] ?? '');
|
||||
|
||||
//create token object ?
|
||||
return Token(
|
||||
json[loginAccessTokenKey] ?? '', json[loginRefreshTokenKey] ?? '');
|
||||
return Token(json[loginAccessTokenKey] ?? '',
|
||||
json[loginRefreshTokenKey] ?? '', '', 0, 0);
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {loginRefreshTokenKey: refreshToken};
|
||||
Map<String, String> refreshTokenToJson() =>
|
||||
{loginRefreshTokenKey: refreshToken};
|
||||
|
||||
Map<String, String> accessTokenToJson() => {loginAccessTokenKey: accessToken};
|
||||
|
||||
Map<String, dynamic> decodeToken() {
|
||||
static Map<String, dynamic> decodeToken(String accessToken) {
|
||||
final parts = accessToken.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid access token');
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
|
||||
class UserModel {
|
||||
static String userUuidKey = 'userUuid';
|
||||
final String? uuid;
|
||||
final String? email;
|
||||
final String? name;
|
||||
@ -36,13 +37,9 @@ class UserModel {
|
||||
|
||||
//uuid to json
|
||||
|
||||
Map<String, dynamic> uuIdAsJson() => {
|
||||
'userUuid': uuid,
|
||||
};
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Token token) {
|
||||
Map<String, dynamic> tempJson = token.decodeToken();
|
||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||
|
||||
return UserModel(
|
||||
uuid: tempJson['uuid'].toString(),
|
||||
|
||||
Reference in New Issue
Block a user