Last active
March 9, 2022 13:23
-
-
Save vemarav/b23d7f2fd62a066dda230301334923d9 to your computer and use it in GitHub Desktop.
Flutter Authentication Fllow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:shared_preferences/shared_preferences.dart'; | |
class AuthUtils { | |
static final String endPoint = '/api/v1/auth_user'; | |
// Keys to store and fetch data from SharedPreferences | |
static final String authTokenKey = 'auth_token'; | |
static final String userIdKey = 'user_id'; | |
static final String nameKey = 'name'; | |
static final String roleKey = 'role'; | |
static String getToken(SharedPreferences prefs) { | |
return prefs.getString(authTokenKey); | |
} | |
static insertDetails(SharedPreferences prefs, var response) { | |
prefs.setString(authTokenKey, response['auth_token']); | |
var user = response['user']; | |
prefs.setInt(userIdKey, user['id']); | |
prefs.setString(nameKey, user['name']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment