Add addSession and removeSession function

This commit is contained in:
Moe Poi ~ 2022-04-28 17:55:46 +07:00
parent 1dc148a3f8
commit 2bcd785352

View file

@ -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');
}