♻️(front) add option to disable silent login

When displayed in an iframe, not being logged-in causes a redirection
to the home page. Which is not what we want with the SDK integration.
We just want to stay on the same page.
This commit is contained in:
Nathan Vasse
2025-02-10 16:34:16 +01:00
committed by NathanVss
parent fb0c9b766d
commit 8818d12ee9
2 changed files with 15 additions and 4 deletions

View File

@@ -10,7 +10,13 @@ import { attemptSilentLogin, canAttemptSilentLogin } from '../utils/silentLogin'
* Here our wrapper just returns false in that case, without triggering an error:
* this is done to prevent unnecessary query retries with react query
*/
export const fetchUser = (): Promise<ApiUser | false> => {
export const fetchUser = (
opts: {
attemptSilent?: boolean
} = {
attemptSilent: true,
}
): Promise<ApiUser | false> => {
return new Promise((resolve, reject) => {
fetchApi<ApiUser>('/users/me')
.then(resolve)
@@ -19,7 +25,7 @@ export const fetchUser = (): Promise<ApiUser | false> => {
if (error instanceof ApiError && error.statusCode === 401) {
// make sure to not resolve the promise while trying to silent login
// so that consumers of fetchUser don't think the work already ended
if (canAttemptSilentLogin()) {
if (opts.attemptSilent && canAttemptSilentLogin()) {
attemptSilentLogin(300)
} else {
resolve(false)