fix: login workflow
parent
e8819f1601
commit
fe753afe85
|
@ -21,7 +21,7 @@ class LoginManager {
|
|||
Future<User> getUser() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final userString = prefs.getString("user");
|
||||
return userString != null ? jsonDecode(userString) : null;
|
||||
return userString != null ? User.fromJson(jsonDecode(userString)) : null;
|
||||
}
|
||||
|
||||
// Throws error status code if it occurs
|
||||
|
@ -41,12 +41,20 @@ class LoginManager {
|
|||
await loginApiProvider.verifyOtp(otp, this.nonce, this.clientid);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString("token", jwt);
|
||||
|
||||
print("JWT: $jwt");
|
||||
|
||||
// Parse jwt to get userid
|
||||
final parts = jwt.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid token');
|
||||
}
|
||||
final payload = utf8.decode(base64Url.decode(parts[1]));
|
||||
|
||||
String payloadString = parts[1];
|
||||
|
||||
while (((payloadString.length * 6) % 8) != 0) payloadString += "=";
|
||||
|
||||
final payload = utf8.decode(base64Url.decode(payloadString));
|
||||
final payloadMap = json.decode(payload);
|
||||
final userId = payloadMap['userid'];
|
||||
// Get user data
|
||||
|
|
|
@ -40,7 +40,7 @@ class Welcome extends StatelessWidget {
|
|||
case "welcome/register":
|
||||
builder =
|
||||
(BuildContext _) => RegisterPage(homeCallback: () {
|
||||
Navigator.pushNamed(context, 'home');
|
||||
Navigator.pushNamed(context, '/home');
|
||||
});
|
||||
break;
|
||||
case "welcome/login":
|
||||
|
@ -51,7 +51,7 @@ class Welcome extends StatelessWidget {
|
|||
builder = (BuildContext _) => OtpPage(
|
||||
loginManager: loginManager,
|
||||
homeCallback: () {
|
||||
Navigator.pushNamed(context, 'home');
|
||||
Navigator.pushNamed(context, '/home');
|
||||
});
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue