mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 02:24:55 +00:00
Added Login with email model instead of json encode
This commit is contained in:
23
lib/features/auth/model/login_with_email_model.dart
Normal file
23
lib/features/auth/model/login_with_email_model.dart
Normal file
@ -0,0 +1,23 @@
|
||||
class LoginWithEmailModel {
|
||||
final String email;
|
||||
final String password;
|
||||
|
||||
LoginWithEmailModel({
|
||||
required this.email,
|
||||
required this.password,
|
||||
});
|
||||
|
||||
factory LoginWithEmailModel.fromJson(Map<String, dynamic> json) {
|
||||
return LoginWithEmailModel(
|
||||
email: json['email'],
|
||||
password: json['password'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'email': email,
|
||||
'password': password,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
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';
|
||||
@ -30,4 +33,13 @@ class Token {
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {loginRefreshToken: refreshToken};
|
||||
|
||||
Map<String, dynamic> decodeToken() {
|
||||
final parts = accessToken.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid access token');
|
||||
}
|
||||
final payload = decodeBase64(parts[1]);
|
||||
return json.decode(payload);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'package:syncrow_app/features/auth/model/token.dart';
|
||||
|
||||
class UserModel {
|
||||
final String? id;
|
||||
final String? email;
|
||||
@ -43,10 +45,12 @@ class UserModel {
|
||||
}
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Map<String, dynamic> json) {
|
||||
factory UserModel.fromToken(Token token) {
|
||||
Map<String, dynamic> tempJson = token.decodeToken();
|
||||
|
||||
return UserModel(
|
||||
id: json['userId'].toString(),
|
||||
email: json['email'],
|
||||
id: tempJson['userId'].toString(),
|
||||
email: tempJson['email'],
|
||||
name: null,
|
||||
photoUrl: null,
|
||||
phoneNumber: null,
|
||||
|
||||
Reference in New Issue
Block a user