Back

How to keep a user authenticated until he logs out manually ?

  • 0
  • Web
  • Databases
  • Accounts
  • General
  • Users
Мухаммадамин
28 Jan, 2024, 11:28

Now, I'm doing a task manager project like Trello so it is natural that the user should be kept until he manually logs out from the app. How can I keep the user authenticated until log out?

  • if I use ApiKey it gets other users' data
  • if I use JWT has a fixed 15-minute limit (and there is no feature like refresh token )

Is there any best practice?

TL;DR
The developer is seeking a solution for keeping a user authenticated until they manually log out of the app in a task manager project similar to Trello. They have tried using ApiKey and JWT but encountered limitations. They are open to suggestions and want to know the best practice for this scenario.
kamal.panara
28 Jan, 2024, 11:46

@Мухаммадамин You are using server SDK with JWT for fetching user specific data from database. now while you are using JWT, i believe you are also using client SDK to createJWT?

according to this docs: https://appwrite.io/docs/products/auth/jwt

You need user to be logged in using client SDK to create JWT token, and you can always create new JWT token if the request fails and try again. because user will be logged in until logs out manually or whatever session length you have set from Appwrite console auth.

So basically, you can approch it like this: you can read the error response of failed request and in case of expiry of existing JWT token, create new JWT and send new request with that JWT.

Мухаммадамин
28 Jan, 2024, 11:53

It's really great idea, thank you again! I'll try this way.

Мухаммадамин
28 Jan, 2024, 11:55

I'll leave this post unsolved for a few days, maybe others have ideas to share

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