@@ -59,7 +59,7 @@ interface CreateLoginComponentOptions extends AuthConfig {
59
59
}
60
60
61
61
interface CreateHrefForProviderOptions {
62
- basePath : string
62
+ redirectPath : string
63
63
loginMethod : AuthConfig [ 'loginMethod' ]
64
64
projectId : string
65
65
url : string
@@ -69,10 +69,10 @@ function createHrefForProvider({
69
69
loginMethod = 'dual' ,
70
70
projectId,
71
71
url,
72
- basePath ,
72
+ redirectPath ,
73
73
} : CreateHrefForProviderOptions ) {
74
74
const params = new URLSearchParams ( )
75
- params . set ( 'origin' , `${ window . location . origin } ${ basePath } ` )
75
+ params . set ( 'origin' , `${ window . location . origin } ${ redirectPath } ` )
76
76
params . set ( 'projectId' , projectId )
77
77
78
78
// Setting `type=token` will return the sid as part of the _query_, which may end up in
@@ -96,7 +96,9 @@ export function createLoginComponent({
96
96
} : CreateLoginComponentOptions ) {
97
97
const useClient = createHookFromObservableFactory ( getClient )
98
98
99
- function LoginComponent ( { projectId, basePath} : LoginComponentProps ) {
99
+ function LoginComponent ( { projectId, ...props } : LoginComponentProps ) {
100
+ const redirectPath = props . redirectPath || props . basePath || '/'
101
+
100
102
const [ providers , setProviders ] = useState < AuthProvider [ ] | null > ( null )
101
103
const [ error , setError ] = useState < unknown > ( null )
102
104
if ( error ) throw error
@@ -113,24 +115,24 @@ export function createLoginComponent({
113
115
114
116
// only create a direct URL if `redirectOnSingle` is true and there is only
115
117
// one provider available
116
- const redirectUrl =
118
+ const redirectUrlForRedirectOnSingle =
117
119
redirectOnSingle &&
118
120
providers ?. length === 1 &&
119
121
providers ?. [ 0 ] &&
120
122
createHrefForProvider ( {
121
123
loginMethod,
122
124
projectId,
123
125
url : providers [ 0 ] . url ,
124
- basePath ,
126
+ redirectPath ,
125
127
} )
126
128
127
- const loading = ! providers || redirectUrl
129
+ const loading = ! providers || redirectUrlForRedirectOnSingle
128
130
129
131
useEffect ( ( ) => {
130
- if ( redirectUrl ) {
131
- window . location . href = redirectUrl
132
+ if ( redirectUrlForRedirectOnSingle ) {
133
+ window . location . href = redirectUrlForRedirectOnSingle
132
134
}
133
- } , [ redirectUrl ] )
135
+ } , [ redirectUrlForRedirectOnSingle ] )
134
136
135
137
if ( loading ) {
136
138
return < LoadingBlock showText />
@@ -153,7 +155,7 @@ export function createLoginComponent({
153
155
loginMethod,
154
156
projectId,
155
157
url : provider . url ,
156
- basePath ,
158
+ redirectPath ,
157
159
} ) }
158
160
mode = "ghost"
159
161
size = "large"
0 commit comments