auth-js
auth-js copied to clipboard
Angular application started polluting logs with exception.
Bug report
Describe the bug
The simple angular application started polluting logs.
To Reproduce
app.module.ts
in AppModule
export const initializer1 =
(
): (() => Promise<boolean>) =>
async () => {
const supabase = createClient(
'url',
'key',
{
auth: {
debug: true,
}
}
);
supabase.auth.onAuthStateChange(() => {});
return true;
};
{
provide: APP_INITIALIZER,
useFactory: initializer1,
multi: true,
},
Expected behavior
No errors in Zone
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: macOS, centos
- Browser chrome
- Version of supabase-js: [^2.39.12]
- Version of Node.js: [e.g. 20.10.0]
Additional context
Debug output in the browser console from GoTrue
GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.619Z #_acquireLock begin -1
render-document-frontend-impl.ts:80 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.619Z #onAuthStateChange() registered callback with id 83bf91bd-ddb2-4add-803e-0e3b2cf2b78d
render-document-frontend-impl.ts:89 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.619Z #onAuthStateChange() registered callback with id a347217b-4993-4ee7-af13-921531e6c12e
core.mjs:26656 Angular is running in development mode.
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.643Z #_acquireLock lock acquired for storage key sb-guksenxnyizhahqwwusz-auth-token
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_initialize() begin is PKCE flow false
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_recoverAndRefresh() begin
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_recoverAndRefresh() session from storage null
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_recoverAndRefresh() session is not valid
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_recoverAndRefresh() end
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_handleVisibilityChange()
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_onVisibilityChanged(true) visibilityState visible
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.644Z #_stopAutoRefresh()
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.645Z #_startAutoRefresh()
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.645Z #_initialize() end
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.645Z #_acquireLock lock released for storage key sb-guksenxnyizhahqwwusz-auth-token
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.645Z #_acquireLock end
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.645Z #_acquireLock begin -1
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.646Z #_acquireLock begin -1
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.646Z #_acquireLock begin -1
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.658Z #_autoRefreshTokenTick() begin
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.658Z #_acquireLock begin 0
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.690Z #_acquireLock lock acquired for storage key sb-guksenxnyizhahqwwusz-auth-token
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.690Z #_useSession begin
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #__loadSession() begin
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #getSession() session from storage null
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #__loadSession() end
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #_acquireLock lock released for storage key sb-guksenxnyizhahqwwusz-auth-token
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z INITIAL_SESSION callback id 83bf91bd-ddb2-4add-803e-0e3b2cf2b78d session null
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #_useSession end
GoTrueClient.js:131 GoTrueClient@0 (2.62.0) 2023-12-23T09:37:44.691Z #_acquireLock end
zone.js:1043 Unhandled Promise rejection: Acquiring an exclusive Navigator LockManager lock "lock:sb-guksenxnyizhahqwwusz-auth-token" immediately failed ; Zone:
Are there any updates on this? It's flooding my Sentry instance on every visibility change of the window / tab of my application.
Hi there, after some test I found that the issue should be related to the merge of this Pull Request in @supabase/gotrue-js version 2.62.0: https://github.com/supabase/gotrue-js/pull/807 If you try to downgrade @supabase/gotrue-js to version 2.61.0 (the previous one), the problem should disappear. Please Supabase Team can you check and try to solve this issue? Thank you!
Paolo
~nother solution to this is to tell angular to run the create script outside of angular.~
~https://github.com/angular/angular-cli/issues/26395#issuecomment-1840806880~
this.supabase = this.ngZone.runOutsideAngular(() => createClient(environment.supabase.url, environment.supabase.key));
~I don't know if this is just hiding the real issue or not, but my logs are a little cleaner. This also seems required for later versions of angular where SSR is enabled.~
ignore this comment. I still eventually see this error log after enough time
Those logs appear when you set 'debug' to 'true' - you shouldn't need that on unless you are debugging specific aspects of the supabase client connection.
Remove this part of your init:
{
auth: {
debug: true,
}
}
and the logs will disappear...?
@nowfred debug true shows the auth flow. The exception is still in place.
@nowfred debug true shows the auth flow. The exception is still in place.
Lol of course my bad - I came across this because we are debugging potentially related lock collision issues. Will update if I have something useful beyond misreading your initial question.
OK so the issue here is really the console.error invocation, not that this is malfunctioning. Will track down why it's logged like so and move it to console.warn or .log.
There's a block that should properly handle this and not log the error. There may be something funky going on with your transpilation environment maybe, as the condition:
if (e.isAcquireTimeout || e instanceof LockAcquireTimeoutError) {
this._debug('auto refresh token tick lock not available')
} else {
throw e
}
Does not re-throw the error. Anyone able to add a comment in your setup to se what's the type of the error thrown here and what properties it has?
https://github.com/supabase/gotrue-js/blob/master/src/GoTrueClient.ts#L2117-L2121
Consider that it happens once in SPA when page is loading
waiting for fix:
For prod build we use this post-install hook:
const fs = require('fs');
const filesToFix = [
'node_modules/@supabase/gotrue-js/dist/main/lib/locks.js',
'node_modules/@supabase/gotrue-js/dist/module/lib/locks.js',
];
filesToFix.forEach((fileToFix) => {
fs.readFile(fileToFix, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
const re = new RegExp(/\s+throw new NavigatorLockAcquireTimeoutError/, "g");
let result = data.replace(re,
'\n// hide error\n//throw new NavigatorLockAcquireTimeoutError',
);
if (result !== data) {
console.log(`Replaced successfully in ${fileToFix}`);
fs.writeFile(fileToFix, result, 'utf8', function (err) {
if (err) return console.log(err);
});
} else {
console.warn(`No Replacement found in ${fileToFix}`);
}
});
});
I also see a lot of Generator.next
which unfortunately points to using generators instead of Promises, so the issue may be coming because it really is an unhandled promise rejection; but it's lifted somehow into a generator Promise implementation.
Probably related to this bug / report: https://github.com/angular/angular/issues/51328
I solved it temporarily by downgrading supabase gotrue, just add this in the package.json
"overrides": { "@supabase/gotrue-js": "2.54.2" }
The only workaround I've found for now with the latest supabase-js version is:
"overrides": { "@supabase/supabase-js": { "@supabase/auth-js": "2.61.0" } }