Back

want to make user loggedin for long time how can i implement it?

  • 0
  • Web
  • Android
  • Accounts
  • Apple
  • Users
Ahmed
20 May, 2023, 13:01

first two images are for login

TL;DR
The user wants to implement a feature that allows users to stay logged in for a long time. The suggested solution is to use `asyncStorage` to persist user data on the device. When the user logs in, check if there is an active session using `account.get()`. If there is an active session, redirect the user to the suitable page. If not, show the login/signup page and prompt the user to login/signup. This will solve the problem of users being redirected to the login page each time they exit the app.
Ahmed
20 May, 2023, 13:02

i used it signed up and logged into home screen after exiting app i am again redirected to login page i should login again and again..... how can i handle this problem how to make user to stay logged in for long time?

safwan
20 May, 2023, 13:04

What I usually do is have a block of code in the login/signup page (whichever is your default), that first checks whether the user has an active session.

safwan
20 May, 2023, 13:05

If they have an active session, redirect them to the suitable page. If they don't have a session, stay on the page and ask them to login/signup

safwan
20 May, 2023, 13:05

a simple way to do this is to use account.get()

Ahmed
20 May, 2023, 13:06

ohh okay

safwan
20 May, 2023, 13:06

Essentially, if the user has an active session, account.get() will return a response. If there is no session, you will get an AppwriteException, that you can catch.

safwan
20 May, 2023, 13:07

@Ahmed if you have any other questions in this particular topic, please tag me and ask away! For questions on a different issue, please make a new post πŸ˜„

safwan
20 May, 2023, 13:07

Let me know how it goes!

Ahmed
20 May, 2023, 13:08

why new post @safwan ?πŸ₯²

Ahmed
20 May, 2023, 13:08

i'll ask question itself here.

safwan
20 May, 2023, 13:09

no like, if you have question about a different issue, make a new post.

Ahmed
20 May, 2023, 13:09

ohh okay boss

safwan
20 May, 2023, 13:09

if it's the same issue, feel free to ask here!

Ahmed
20 May, 2023, 15:25

can we use asyncStore with it

Ahmed
20 May, 2023, 15:25

?

safwan
21 May, 2023, 05:44

Hey sorry for the late reply just saw this message. asyncStorage is used for persisting data on the device. What do you want to store on the device when a user logs in?

safwan
21 May, 2023, 05:44

@Ahmed

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