Skip to content

Commit 9729bab

Browse files
Avoid using this (#11)
1 parent 009ff4d commit 9729bab

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
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": "2.0.3",
8+
"version": "2.0.4",
99
"keywords": [
1010
"auth",
1111
"user",

src/client.ts

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,44 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
239239
}
240240
}
241241

242+
const getSignupPageUrl = (options?: RedirectToSignupOptions) => {
243+
let qs = ""
244+
if (options && options.postSignupRedirectUrl) {
245+
const encode = window ? window.btoa : btoa;
246+
qs = new URLSearchParams({"rt": encode(options.postSignupRedirectUrl)}).toString()
247+
}
248+
return `${clientState.authUrl}/signup?${qs}`
249+
}
250+
251+
const getLoginPageUrl = (options?: RedirectToLoginOptions) => {
252+
let qs = ""
253+
if (options && options.postLoginRedirectUrl) {
254+
const encode = window ? window.btoa : btoa;
255+
qs = new URLSearchParams({"rt": encode(options.postLoginRedirectUrl)}).toString()
256+
}
257+
return `${clientState.authUrl}/login?${qs}`
258+
}
259+
260+
const getAccountPageUrl = () => {
261+
return `${clientState.authUrl}/account`
262+
}
263+
264+
const getOrgPageUrl = (orgId?: string) => {
265+
if (orgId) {
266+
return `${clientState.authUrl}/org?id=${orgId}`
267+
} else {
268+
return `${clientState.authUrl}/org`
269+
}
270+
}
271+
272+
const getCreateOrgPageUrl = () => {
273+
return `${clientState.authUrl}/create_org`
274+
}
275+
276+
const getSetupSAMLPageUrl = (orgId: string) => {
277+
return `${clientState.authUrl}/saml?id=${orgId}`
278+
}
279+
242280
const client = {
243281
addLoggedInChangeObserver(loggedInChangeObserver: (isLoggedIn: boolean) => void): void {
244282
const hasObserver = clientState.observers.includes(loggedInChangeObserver)
@@ -280,65 +318,51 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
280318
},
281319

282320
getSignupPageUrl(options?: RedirectToSignupOptions): string {
283-
let qs = ""
284-
if (options && options.postSignupRedirectUrl) {
285-
const encode = window ? window.btoa : btoa;
286-
qs = new URLSearchParams({"rt": encode(options.postSignupRedirectUrl)}).toString()
287-
}
288-
return `${clientState.authUrl}/signup?${qs}`
321+
return getSignupPageUrl(options)
289322
},
290323

291324
getLoginPageUrl(options?: RedirectToLoginOptions): string {
292-
let qs = ""
293-
if (options && options.postLoginRedirectUrl) {
294-
const encode = window ? window.btoa : btoa;
295-
qs = new URLSearchParams({"rt": encode(options.postLoginRedirectUrl)}).toString()
296-
}
297-
return `${clientState.authUrl}/login?${qs}`
325+
return getLoginPageUrl(options)
298326
},
299327

300328
getAccountPageUrl(): string {
301-
return `${clientState.authUrl}/account`
329+
return getAccountPageUrl()
302330
},
303331

304332
getOrgPageUrl(orgId?: string): string {
305-
if (orgId) {
306-
return `${clientState.authUrl}/org?id=${orgId}`
307-
} else {
308-
return `${clientState.authUrl}/org`
309-
}
333+
return getOrgPageUrl(orgId)
310334
},
311335

312336
getCreateOrgPageUrl(): string {
313-
return `${clientState.authUrl}/create_org`
337+
return getCreateOrgPageUrl()
314338
},
315339

316340
getSetupSAMLPageUrl(orgId: string): string {
317-
return `${clientState.authUrl}/saml?id=${orgId}`
341+
return getSetupSAMLPageUrl(orgId)
318342
},
319343

320344
redirectToSignupPage(options?: RedirectToSignupOptions): void {
321-
window.location.href = this.getSignupPageUrl(options)
345+
window.location.href = getSignupPageUrl(options)
322346
},
323347

324348
redirectToLoginPage(options?: RedirectToLoginOptions): void {
325-
window.location.href = this.getLoginPageUrl(options)
349+
window.location.href = getLoginPageUrl(options)
326350
},
327351

328352
redirectToAccountPage(): void {
329-
window.location.href = this.getAccountPageUrl()
353+
window.location.href = getAccountPageUrl()
330354
},
331355

332356
redirectToOrgPage(orgId?: string): void {
333-
window.location.href = this.getOrgPageUrl(orgId)
357+
window.location.href = getOrgPageUrl(orgId)
334358
},
335359

336360
redirectToCreateOrgPage(): void {
337-
window.location.href = this.getCreateOrgPageUrl()
361+
window.location.href = getCreateOrgPageUrl()
338362
},
339363

340364
redirectToSetupSAMLPage(orgId: string) {
341-
window.location.href = this.getSetupSAMLPageUrl(orgId)
365+
window.location.href = getSetupSAMLPageUrl(orgId)
342366
},
343367

344368
async logout(redirectAfterLogout: boolean): Promise<void> {

0 commit comments

Comments
 (0)