4
2
Fork 0

fix: login workflow

pull/73/head
Sudharshan S. 2019-07-02 20:28:18 +08:00
parent e8819f1601
commit fe753afe85
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
2 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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: