Comments (9)
Great, if you change the default key, you should probably add a check to see if there is a session on the old namespace to prevent force logging out everyone who updates the library.
from supabase-kt.
I guess you could just provide a custom session manager, which saves sessions to separate keys depending on the build mode:
(this is a straight copy from the default one, see text below)
class CustomSessionManager @OptIn(SupabaseInternal::class) constructor(
settings: Settings = createDefaultSettings()
) : SessionManager {
@OptIn(ExperimentalSettingsApi::class)
private val suspendSettings = settings.toSuspendSettings()
@OptIn(ExperimentalSettingsApi::class, SupabaseInternal::class)
override suspend fun saveSession(session: UserSession) {
suspendSettings.putString(SETTINGS_KEY, supabaseJson.encodeToString(session))
}
@OptIn(ExperimentalSettingsApi::class, SupabaseInternal::class)
override suspend fun loadSession(): UserSession? {
val session = suspendSettings.getStringOrNull(SETTINGS_KEY) ?: return null
return try {
supabaseJson.decodeFromString(session)
} catch(e: Exception) {
Auth.logger.e(e) { "Failed to load session" }
null
}
}
@OptIn(ExperimentalSettingsApi::class)
override suspend fun deleteSession() {
suspendSettings.remove(SETTINGS_KEY)
}
companion object {
private const val SETTINGS_DEBUG_KEY = "session_debug"
private const val SETTINGS_RELEASE_KEY = "session_release"
const val SETTINGS_KEY = if(BuildConfig.DEBUG) SETTINGS_DEBUG_KEY else SETTINGS_RELEASE_KEY
}
}
val supabase = createSupabaseClient(
"url",
"key"
) {
install(Auth) {
sessionManager = CustomSessionManager()
}
}
To make this easier, we could also make it possible to set the SETTINGS_KEY
in the constructor of the "default" SettingsSessionManager()
. So you wouldn't have to create a completely new class
from supabase-kt.
Hi @jan-tennert JS and Flutter SDKs uses the project ref as namespace
- supabase-js https://github.com/supabase/supabase-js/blob/master/src/SupabaseClient.ts#L85
- supabase-flutter https://github.com/supabase/supabase-flutter/blob/main/packages/supabase_flutter/lib/src/supabase.dart#L93
I'll be applying this change to Swift too, and it would be nice if Kotlin had the same behavior.
from supabase-kt.
Right, we should probably do this, and it would solve this issue, but we could still make this configurable.
from supabase-kt.
I can work on this. I will make it configurable and use the project reference as well.
from supabase-kt.
Btw here if I'm getting an UnauthorizedException
, I should be logged out anyway right? Because it's not happening, maybe there's something missing there as well.
from supabase-kt.
If this exception is thrown while refreshing the session, the session should be getting cleared. Otherwise no.
from supabase-kt.
So the flow should be like this: Make call -> if the call is failing refresh -> if the refresh is failing clear.
In that case, the call is failing so the refresh should be called and the refresh should fail as well because the token is wrong and also we keep getting failures. If refresh if successful the next call should succeed but it's not the case.
from supabase-kt.
Not sure if I understand the problem. The library doesn't handle API errors at all, they just get thrown as a RestException (which has some subclasses based on the status code). The only case where RestException get caught is in the auto refresh:
But other than that, exceptions are handled by the application itself
from supabase-kt.
Related Issues (20)
- [Bug]: Column.Raw not removing line breaks
- [Feature request]: Update to Kotlin 2.0.0
- [Bug]: PostgREST filter logical operator unexpected behaviour HOT 1
- [Question]: Is it really necessary that if the authentication with the keys is incorrect it will exit the application with a FATAL ERROR? HOT 2
- [Question]: Is there a possibility to log in anonymously and make it persistent? HOT 6
- [Feature request]: Add support for new private channels
- [Bug]: supabase-runtime fails to connect on iOS devices HOT 3
- [Bug]: Extension functions in RealtimeExt.kt don't have to be suspend HOT 7
- [Question]: Trouble Implementing Password Reset on Android with Supabase HOT 3
- [Feature request]: App To App OAuth for Discord HOT 1
- [Feature request]: Simplify realtime flows for postgres changes
- [Question]: I think it's better to move the samples to root project? HOT 2
- [Feature request]: Improve Exception on Cancellation HOT 2
- [Bug]: [Storage] Empty file is created on Dashboard when pass empty `ByteArray` to upload function
- [Bug]: All object keys must match HOT 13
- [Bug]: Error: Missing one of these types: signup, email_change, sms, phone_change HOT 2
- [Feature request]: remove session, emit `SIGNED_OUT` when JWT `session_id` is invalid
- [Question]: How cancel supabase request? HOT 3
- [Feature request]: Export `SupabaseExperimental` annotation in `compose-auth-ui` plugin HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supabase-kt.