store user info after login

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-06-21 23:58:13 +08:00
parent 23389ef140
commit 8dd218235d
5 changed files with 54 additions and 9 deletions

View File

@ -14,6 +14,8 @@ class HttpType {
static const kAuthResTypeEmailCheck = "email_check";
}
// to-do: The UserPayload does not contain all the fields of the user.
// Is all the fields of the user needed?
class UserPayload {
String id = '';
String name = '';
@ -29,6 +31,16 @@ class UserPayload {
note = json['note'] ?? '',
status = json['status'],
isAdmin = json['is_admin'] == true;
Map<String, dynamic> toJson() {
final Map<String, dynamic> map = {
'name': name,
};
if (status != null) {
map['status'] = status!;
}
return map;
}
}
class PeerPayload {

View File

@ -424,6 +424,8 @@ Future<bool?> loginDialog() async {
if (resp.access_token != null) {
await bind.mainSetLocalOption(
key: 'access_token', value: resp.access_token!);
await bind.mainSetLocalOption(
key: 'user_info', value: jsonEncode(resp.user ?? {}));
close(true);
return;
}
@ -482,12 +484,8 @@ Future<bool?> loginDialog() async {
curOP: curOP,
cbLogin: (Map<String, dynamic> authBody) {
try {
final loginResp =
gFFI.userModel.getLoginResponseFromAuthBody(authBody);
if (loginResp.access_token != null) {
bind.mainSetLocalOption(
key: 'access_token', value: loginResp.access_token!);
}
// access_token is already stored in the rust side.
gFFI.userModel.getLoginResponseFromAuthBody(authBody);
} catch (e) {
debugPrint('Failed too parse oidc login body: "$authBody"');
}