From 11a0fbc406b03ffd31304bf64a3033b8ca8de223 Mon Sep 17 00:00:00 2001 From: Stojan Dimitrovski Date: Mon, 23 Jan 2023 11:06:26 +0100 Subject: [PATCH] feat: add `skipBrowserRedirect` option to `signInWithOAuth` (#575) Allows for custom handling of the redirect URL when in browser environments. Fixes: #417 --- src/GoTrueClient.ts | 4 +++- src/lib/types.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index 76c5e4747..3a064b2ff 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -352,6 +352,7 @@ export default class GoTrueClient { redirectTo: credentials.options?.redirectTo, scopes: credentials.options?.scopes, queryParams: credentials.options?.queryParams, + skipBrowserRedirect: credentials.options?.skipBrowserRedirect, }) } @@ -933,6 +934,7 @@ export default class GoTrueClient { redirectTo?: string scopes?: string queryParams?: { [key: string]: string } + skipBrowserRedirect?: boolean } = {} ) { const url: string = this._getUrlForProvider(provider, { @@ -941,7 +943,7 @@ export default class GoTrueClient { queryParams: options.queryParams, }) // try to open on the browser - if (isBrowser()) { + if (isBrowser() && !options.skipBrowserRedirect) { window.location.assign(url) } return { data: { provider, url }, error: null } diff --git a/src/lib/types.ts b/src/lib/types.ts index df5e4de46..64ded0654 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -440,6 +440,8 @@ export type SignInWithOAuthCredentials = { scopes?: string /** An object of query params */ queryParams?: { [key: string]: string } + /** If set to true does not immediately redirect the current browser context to visit the OAuth authorization page for the provider. */ + skipBrowserRedirect?: boolean } } @@ -912,8 +914,8 @@ export type CallRefreshTokenResult = export type Pagination = { [key: string]: any - nextPage: number | null, - lastPage: number, + nextPage: number | null + lastPage: number total: number }