-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-refreshing of tokens can fail and never restart again #630
Comments
We are also experiencing a ridiculous amount of people that log into our app, use it every day, but on the third day or so, their session is completely gone. This is breaking their ability to even utilize our app. We rely on this code that initializes on app start. We then utilize the authJWT to authenticate and identify our users on every backend API call. But the session becomes nil, and thus everything is set to nil. for await (event, session) in await supabase.auth.authStateChanges { Please, can we have eyes on this issue? This is a high severity issue. |
Hi, thanks for reporting this issue, I'll be working on it ASAP. In the meanwhile, if anyone has a fix for it, feel free to PR it and I'll gladly review it. |
Hi @vojtabohm and @AlanDuong07 could you confirm which version of the library are you using? |
@vojtabohm I wasn't able to reproduce by using airplane mode and using latest version of the library, please note that there are no |
Hi, we were on version 2.20.4 I believe. I have since upgraded to the latest version. Though looking through the update notes, I don't see many changes regarding dropped sessions. I will let you know if the problem magically goes away with the latest update. Could I please get help with whether my use of Supabase Swift is correct @grdsdev? Only with the usual initialization code for Supabase Swift SDK, I initialize on app launch, this code that listens to auth state:
On user sign in with apple / google, I use That should trigger the authStateChanges listener to have a session, so I can save the authJWT in memory as the docs recommend. I reassign the authJWT when new session data comes in. Yet after a few days or so, users have an auth JWT of nil! The entire session, in fact, becomes undefined, because both "self.authJWT and self.supabaseUserId" become nil and stay nil. How could this be happening? This is the only code I use to handle Supabase Auth. Isn't it that simple, or am I missing something? |
Your usage of the SDK seems fine, could you attach a logger on initialization and send logs over? You can use the example: struct AppLogger: SupabaseLogger {
func log(message: SupabaseLogMessage) {
print(message.description)
}
}
let client = SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "public-anon-key",
options: SupabaseClientOptions(
global: SupabaseClientOptions.GlobalOptions(
logger: AppLogger()
)
)
) |
Bug report
Describe the bug
When the refresh of a token fails (e.g. the app went into background or the refresh API call fails for plethora of reasons) the library silently fails and never refreshes the token again.
_ = try? await refreshSession(refreshedSession.refreshToken)
(in thescheduleNextTokenRefresh
function).To Reproduce
Set your phone into airplane mode, wait for refresh to fail. It will never refresh again since
scheduleNextTokenRefresh
is called recursively fromrefreshSession
that can fail, it will be stopped.If you follow the docs recommendation
basically something like this:
and you rely on
authStateChanges
to always give you a token, then you can run into issue of token failing to refresh and you're forever stuck with the old one.Expected behavior
It would be great to incorporate some sort of retry mechanism. I worked around this with storing the entire session, not just the token and manually refreshing if it's expired.
I think this is a good work-around so if a retry mechanism is too complicated (which is understandable), perhaps update of the docs could be in order.
The text was updated successfully, but these errors were encountered: