mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
Semi-implemented getting spaces feature
This commit is contained in:
@ -4,8 +4,8 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_app/utils/helpers/decode_base64.dart';
|
||||
|
||||
class Token {
|
||||
static const String loginAccessToken = 'access_token';
|
||||
static const String loginRefreshToken = 'refreshToken';
|
||||
static const String loginAccessTokenKey = 'access_token';
|
||||
static const String loginRefreshTokenKey = 'refreshToken';
|
||||
|
||||
final String accessToken;
|
||||
final String refreshToken;
|
||||
@ -16,6 +16,10 @@ class Token {
|
||||
|
||||
bool get accessTokenIsNotEmpty => accessToken.isNotEmpty;
|
||||
|
||||
bool get refreshTokenIsNotEmpty => refreshToken.isNotEmpty;
|
||||
|
||||
bool get isNotEmpty => accessToken.isNotEmpty && refreshToken.isNotEmpty;
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
@ -26,13 +30,17 @@ class Token {
|
||||
factory Token.fromJson(Map<String, dynamic> json) {
|
||||
//save token to secure storage
|
||||
var storage = const FlutterSecureStorage();
|
||||
storage.write(key: loginAccessToken, value: json[loginAccessToken] ?? '');
|
||||
storage.write(
|
||||
key: loginAccessTokenKey, value: json[loginAccessTokenKey] ?? '');
|
||||
|
||||
//create token object ?
|
||||
return Token(json[loginAccessToken] ?? '', json[loginRefreshToken] ?? '');
|
||||
return Token(
|
||||
json[loginAccessTokenKey] ?? '', json[loginRefreshTokenKey] ?? '');
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {loginRefreshToken: refreshToken};
|
||||
Map<String, String> toJson() => {loginRefreshTokenKey: refreshToken};
|
||||
|
||||
Map<String, String> accessTokenToJson() => {loginAccessTokenKey: accessToken};
|
||||
|
||||
Map<String, dynamic> decodeToken() {
|
||||
final parts = accessToken.split('.');
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
|
||||
class UserModel {
|
||||
final String? id;
|
||||
final String? uuid;
|
||||
final String? email;
|
||||
final String? name;
|
||||
final String? photoUrl;
|
||||
@ -12,18 +12,8 @@ class UserModel {
|
||||
|
||||
final bool? isAgreementAccepted;
|
||||
|
||||
//token decoded with jwt
|
||||
//{
|
||||
// "email": "Test@Test.com",
|
||||
// "userId": 2,
|
||||
// "uuid": "e145438c-4c62-4535-a0f4-f77958f9f9f4",
|
||||
// "sessionId": "0409a7a1-6ef5-42c5-b3a1-1f15c639b301",
|
||||
// "iat": 1709711675,
|
||||
// "exp": 1709711975
|
||||
// }
|
||||
|
||||
UserModel({
|
||||
required this.id,
|
||||
required this.uuid,
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.photoUrl,
|
||||
@ -34,7 +24,7 @@ class UserModel {
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
id: json['id'],
|
||||
uuid: json['id'],
|
||||
email: json['email'],
|
||||
name: json['name'],
|
||||
photoUrl: json['photoUrl'],
|
||||
@ -44,12 +34,18 @@ class UserModel {
|
||||
);
|
||||
}
|
||||
|
||||
//uuid to json
|
||||
|
||||
Map<String, dynamic> uuIdAsJson() => {
|
||||
'userUuid': uuid,
|
||||
};
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Token token) {
|
||||
Map<String, dynamic> tempJson = token.decodeToken();
|
||||
|
||||
return UserModel(
|
||||
id: tempJson['uuid'].toString(),
|
||||
uuid: tempJson['uuid'].toString(),
|
||||
email: tempJson['email'],
|
||||
name: null,
|
||||
photoUrl: null,
|
||||
@ -61,7 +57,7 @@ class UserModel {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'id': uuid,
|
||||
'email': email,
|
||||
'name': name,
|
||||
'photoUrl': photoUrl,
|
||||
|
Reference in New Issue
Block a user