Skip to content
Back

[Solved] logining out and logining in with a different user logs me back as first user

  • 0
  • Accounts
  • Flutter
🍜Udon🍜
19 May, 2023, 15:35

In the final client = Appwrite()..setEndpoint()..setProject()..persistSession=false;

TL;DR
User is having an issue where logging out and logging in with a different user logs them back in as the first user. The issue was found to be with the way authentication was being handled. The solution is to use the Account.deleteSession() function to delete the current session and then clear the local storage data using the LocalStorage.clear() function.
🍜Udon🍜
19 May, 2023, 15:35

I'm gonna try that

🍜Udon🍜
19 May, 2023, 15:39

Oh nvm that variable doesn't exist but I'm gonna try ```import 'package:flutter/services.dart' show rootBundle; import 'package:localstorage/localstorage.dart';

// Create an instance of LocalStorage final LocalStorage storage = LocalStorage('my_app');

// Function to clear the stored session data Future<void> clearSessionData() async { await storage.clear(); }

// Call clearSessionData after deleting the session await Account.deleteSession(sessionId); await clearSessionData();```

🍜Udon🍜
19 May, 2023, 15:40

Then I'm gonna try reloading the page with ```import 'package:flutter_inappwebview/flutter_inappwebview.dart';

// Function to reload the web page Future<void> reloadWebPage() async { await InAppWebViewController?.instance?.reload(); }

// Call reloadWebPage after clearing the session data await clearSessionData(); await reloadWebPage();```

Drake
19 May, 2023, 15:41

Then login with user B and it logs me in as user A.

So. what makes you say this?

Drake
19 May, 2023, 15:42

I checked the code for the SDK and confirmed we handle all of this already so you shouldn't have to do any of this.

🍜Udon🍜
19 May, 2023, 15:44

Nevermund inappwebview isn't supported for web

🍜Udon🍜
19 May, 2023, 15:44

Oh wow

🍜Udon🍜
19 May, 2023, 15:44

Yeah it's probably something I'm doing wrong

🍜Udon🍜
19 May, 2023, 15:48

It does tell me Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.

Drake
19 May, 2023, 15:48

perhaps you have something saved in your application state

🍜Udon🍜
19 May, 2023, 15:48

That could be it too

Drake
19 May, 2023, 15:48

right. once you delete your session. the local storage value should be cleared

🍜Udon🍜
19 May, 2023, 15:49

Just making sure it's something weird in doing

🍜Udon🍜
19 May, 2023, 15:49

Can you explain that more or show me

Drake
19 May, 2023, 15:49

chrome dev tools > Application > Local Storage

🍜Udon🍜
19 May, 2023, 15:50

Ahh okay

🍜Udon🍜
19 May, 2023, 15:51

There's no way to force that?

Drake
19 May, 2023, 15:51
🍜Udon🍜
19 May, 2023, 15:52

Gotcha

🍜Udon🍜
19 May, 2023, 16:15

How can I get the current sessionId is it the same as the uid

🍜Udon🍜
19 May, 2023, 16:21

Okay will do thanks

🍜Udon🍜
19 May, 2023, 17:07

I think I found the problem. It's the way I'm handling authentication I tried doing it a different way but I found a good way that should work. Thanks alot @Steven

🍜Udon🍜
19 May, 2023, 17:07

[Solved] logining out and logining in with a different user logs me back as first user

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more