Skip to content

Commit 5c33051

Browse files
Add redirecting back to a URL after login/signup if specified
1 parent 4c98996 commit 5c33051

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"url": "https://github.com/PropelAuth/javascript"
77
},
8-
"version": "1.2.4",
8+
"version": "1.2.5",
99
"keywords": [
1010
"auth",
1111
"user",

src/client.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ const LOGGED_OUT_AT_KEY = "__PROPEL_AUTH_LOGGED_OUT_AT"
66
const AUTH_TOKEN_REFRESH_BEFORE_EXPIRATION_SECONDS = 4 * 60
77
const DEBOUNCE_DURATION_FOR_REFOCUS_SECONDS = 4 * 60
88

9+
export interface RedirectToSignupOptions {
10+
postSignupRedirectUrl: string
11+
}
12+
13+
export interface RedirectToLoginOptions {
14+
postLoginRedirectUrl: string
15+
}
16+
917
export interface IAuthClient {
1018
/**
1119
* If the user is logged in, this method returns an access token, the time (in seconds) that the token will expire,
@@ -28,12 +36,12 @@ export interface IAuthClient {
2836
/**
2937
* Redirects the user to the signup page.
3038
*/
31-
redirectToSignupPage(): void
39+
redirectToSignupPage(options?: RedirectToSignupOptions): void
3240

3341
/**
3442
* Redirects the user to the login page.
3543
*/
36-
redirectToLoginPage(): void
44+
redirectToLoginPage(options?: RedirectToLoginOptions): void
3745

3846
/**
3947
* Redirects the user to the account page.
@@ -230,12 +238,22 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
230238
}
231239
},
232240

233-
redirectToSignupPage(): void {
234-
window.location.href = `${clientState.authUrl}/signup`
241+
redirectToSignupPage(options?: RedirectToSignupOptions): void {
242+
let qs = ""
243+
if (options && options.postSignupRedirectUrl) {
244+
const encode = window ? window.btoa : btoa;
245+
qs = new URLSearchParams({"rt": encode(options.postSignupRedirectUrl)}).toString()
246+
}
247+
window.location.href = `${clientState.authUrl}/signup?${qs}`
235248
},
236249

237-
redirectToLoginPage(): void {
238-
window.location.href = `${clientState.authUrl}/login`
250+
redirectToLoginPage(options?: RedirectToLoginOptions): void {
251+
let qs = ""
252+
if (options && options.postLoginRedirectUrl) {
253+
const encode = window ? window.btoa : btoa;
254+
qs = new URLSearchParams({"rt": encode(options.postLoginRedirectUrl)}).toString()
255+
}
256+
window.location.href = `${clientState.authUrl}/login?${qs}`
239257
},
240258

241259
redirectToAccountPage(): void {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type { AuthenticationInfo, User } from "./api"
22
export { createClient } from "./client"
3-
export type { IAuthClient, IAuthOptions } from "./client"
3+
export type { IAuthClient, IAuthOptions, RedirectToSignupOptions, RedirectToLoginOptions } from "./client"
44
export { UserRole } from "./org"
55
export type { OrgIdToOrgMemberInfo, OrgMemberInfo } from "./org"
66
export type { OrgHelper } from "./org_helper"

0 commit comments

Comments
 (0)