Skip to content

Commit

Permalink
chore(demos): remove shared preferences on logout (#180)
Browse files Browse the repository at this point in the history
* chore(demos): remove sharedpreferences on logout

* chore: remove log

---------

Co-authored-by: DominicGBauer <dominic@nomanini.com>
  • Loading branch information
DominicGBauer and DominicGBauer authored Sep 30, 2024
1 parent c01d844 commit 0301d16
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
3 changes: 0 additions & 3 deletions demos/django-todolist/lib/api_client.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';

final log = Logger('powersync-django-todolist');

class ApiClient {
final String baseUrl;
Expand Down
5 changes: 3 additions & 2 deletions demos/django-todolist/lib/powersync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import './app_config.dart';
import './models/schema.dart';

final log = Logger('powersync-django');
final prefs = SharedPreferencesAsync();

/// Postgres Response codes that we cannot recover from by retrying.
final List<RegExp> fatalResponseCodes = [
Expand Down Expand Up @@ -89,8 +90,7 @@ bool _dbInitialized = false;

/// id of the user currently logged in
Future<String?> getUserId() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString('id');
return await prefs.getString('id');
}

Future<bool> isLoggedIn() async {
Expand Down Expand Up @@ -129,5 +129,6 @@ Future<void> openDatabase() async {

/// Explicit sign out - clear database and log out.
Future<void> logout() async {
await prefs.remove('id');
await db.disconnectAndClear();
}
2 changes: 0 additions & 2 deletions demos/django-todolist/lib/widgets/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:powersync_django_todolist_demo/api_client.dart';
import 'package:powersync_django_todolist_demo/app_config.dart';
import 'package:powersync_django_todolist_demo/powersync.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../main.dart';

Expand Down Expand Up @@ -42,7 +41,6 @@ class _LoginPageState extends State<LoginPage> {

final payload = _parseJwt(session['access_token']);
if (payload.containsKey('sub')) {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('id', payload['sub'].toString());

//re-init PowerSync manually for first time sign in
Expand Down

0 comments on commit 0301d16

Please sign in to comment.