Skip to content

Instantly share code, notes, and snippets.

@vemarav
Last active March 9, 2022 13:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vemarav/b23d7f2fd62a066dda230301334923d9 to your computer and use it in GitHub Desktop.
Save vemarav/b23d7f2fd62a066dda230301334923d9 to your computer and use it in GitHub Desktop.
Flutter Authentication Fllow
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