app/lib/data/auth.dart

26 lines
No EOL
696 B
Dart

import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
String getSession(userId, sessionToken) {
var sessionData = {
"user_id": userId,
"session_token": sessionToken
};
var sessionRaw = jsonEncode(sessionData).toString();
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');
}