2022-04-28 12:54:56 +02:00
|
|
|
import 'dart:convert';
|
2022-04-28 12:55:46 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-04-28 12:54:56 +02:00
|
|
|
|
2022-05-12 13:16:41 +02:00
|
|
|
String getEncodedSession(userId, sessionToken) {
|
2022-04-28 12:54:56 +02:00
|
|
|
var sessionData = {
|
|
|
|
"user_id": userId,
|
|
|
|
"session_token": sessionToken
|
|
|
|
};
|
|
|
|
var sessionRaw = jsonEncode(sessionData).toString();
|
|
|
|
var sessionEncoded = base64.encode(utf8.encode(sessionRaw));
|
|
|
|
return sessionEncoded;
|
2022-04-28 12:55:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> addSession(userId, sessionToken) async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
2022-05-12 13:16:41 +02:00
|
|
|
String session = getEncodedSession(userId, sessionToken);
|
2022-04-28 12:55:46 +02:00
|
|
|
|
|
|
|
await prefs.setString('session', session);
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:13:10 +02:00
|
|
|
Future<bool> checkSessionExist() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
if (prefs.containsKey('session')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-28 12:55:46 +02:00
|
|
|
Future<void> removeSession() async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
await prefs.remove('session');
|
2022-04-28 12:54:56 +02:00
|
|
|
}
|