Skip to content

Commit

Permalink
feat: add skipBrowserRedirect option to signInWithOAuth (#575)
Browse files Browse the repository at this point in the history
Allows for custom handling of the redirect URL when in browser
environments.

Fixes: #417
  • Loading branch information
hf authored Jan 23, 2023
1 parent faaaad2 commit 11a0fbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export default class GoTrueClient {
redirectTo: credentials.options?.redirectTo,
scopes: credentials.options?.scopes,
queryParams: credentials.options?.queryParams,
skipBrowserRedirect: credentials.options?.skipBrowserRedirect,
})
}

Expand Down Expand Up @@ -933,6 +934,7 @@ export default class GoTrueClient {
redirectTo?: string
scopes?: string
queryParams?: { [key: string]: string }
skipBrowserRedirect?: boolean
} = {}
) {
const url: string = this._getUrlForProvider(provider, {
Expand All @@ -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 }
Expand Down
6 changes: 4 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 11a0fbc

Please sign in to comment.