Add addSession and removeSession function
This commit is contained in:
parent
1dc148a3f8
commit
2bcd785352
1 changed files with 15 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
String getSession(userId, sessionToken) {
|
||||
var sessionData = {
|
||||
|
@ -9,3 +10,17 @@ String getSession(userId, sessionToken) {
|
|||
var sessionEncoded = base64.encode(utf8.encode(sessionRaw));
|
||||
return sessionEncoded;
|
||||
}
|
||||
|
||||
Future<void> addSession(userId, sessionToken) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
String session = getSession(userId, sessionToken);
|
||||
|
||||
await prefs.setString('session', session);
|
||||
}
|
||||
|
||||
Future<void> removeSession() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
await prefs.remove('session');
|
||||
}
|
Loading…
Reference in a new issue