Back

how can I save the session so that it does not request authorization again?

  • 0
  • Android
Steven
7 Mar, 2025, 21:12

are you using the android SDK? If so, this is done automatically.

See https://appwrite.io/docs/advanced/security/authentication#persistence

TL;DR
Developers want to save session for authorization without repeat login. They suggest using SharedPreferencesCookieStore for Android. Recommendation: 1. On app start, call account.get() 2. If successful, proceed to authenticated screen 3. If unsuccessful, redirect to login page The Android SDK automatically handles saving the session when using it. Use account.get() to check authorization status and handle accordingly.
EmoKid
7 Mar, 2025, 21:12

i use android web application

EmoKid
7 Mar, 2025, 21:13

from appwrite lib

Steven
7 Mar, 2025, 21:13

sorry i don't understand

EmoKid
7 Mar, 2025, 21:13

a moment

EmoKid
7 Mar, 2025, 21:13

its not sdk?

TypeScript
account.createOAuth2Session(
                            activity = context as ComponentActivity,
                            provider = OAuthProvider.YANDEX,
                        )
Steven
7 Mar, 2025, 21:14

what package did you install?

EmoKid
7 Mar, 2025, 21:14
TypeScript
implementation("io.appwrite:sdk-for-android:6.1.0")```
Steven
7 Mar, 2025, 21:15

right that's the android sdk

Steven
7 Mar, 2025, 21:15

so it's done automatically

Steven
7 Mar, 2025, 21:15

so what you should do is:

  1. app start
  2. call account.get()
  3. if successful, proceed to authenticated screen
  4. if unsuccessful, redirect to login page
EmoKid
7 Mar, 2025, 21:16

is it possible for me to just save the session and write it to SharedPreferences and then?

Steven
7 Mar, 2025, 21:17

i do not recomment this. you end up with a weird source of truth

EmoKid
7 Mar, 2025, 21:22

What would be better?

Steven
7 Mar, 2025, 21:23

so what you should do is:

  1. app start
  2. call account.get()
  3. if successful, proceed to authenticated screen
  4. if unsuccessful, redirect to login page
EmoKid
7 Mar, 2025, 21:25
TypeScript
if(account.get()){


}else{

}
EmoKid
7 Mar, 2025, 21:25

right?

Steven
7 Mar, 2025, 21:27

try/catch

Steven
7 Mar, 2025, 21:27

account.get() will throw an exception on error

EmoKid
7 Mar, 2025, 21:29

i get it

EmoKid
7 Mar, 2025, 21:31

so it won't be stored in the SharePreference right?

Steven
7 Mar, 2025, 21:34
EmoKid
7 Mar, 2025, 21:47

thx

EmoKid
7 Mar, 2025, 21:47

i get it

EmoKid
7 Mar, 2025, 21:47

thank you so much

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