Skip to content

Commit f7f69c6

Browse files
committed
Stop unnecessarily setting screen_hint=sign-in
It's counter-productive to send this parameter because it prevents us from contextually redirecting user's back to the sign-up page when clients are behaving properly.
1 parent ffb8907 commit f7f69c6

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/create-client.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe("create-client", () => {
257257
restoreLocation();
258258
});
259259

260-
it("generates a PKCE challenge and redirects to the AuthKit sign-in page", async () => {
260+
it("generates a PKCE challenge and redirects to AuthKit", async () => {
261261
const { scope } = nockRefresh();
262262
expect(sessionStorage.getItem(storageKeys.codeVerifier)).toBeNull();
263263

@@ -282,7 +282,6 @@ describe("create-client", () => {
282282
provider: "authkit",
283283
redirect_uri: "https://example.com/",
284284
response_type: "code",
285-
screen_hint: "sign-in",
286285
},
287286
});
288287
expect(sessionStorage.getItem(storageKeys.codeVerifier)).toBeDefined();
@@ -341,7 +340,7 @@ describe("create-client", () => {
341340
restoreLocation();
342341
});
343342

344-
it("generates a PKCE challenge and returns the AuthKit sign-in page URL", async () => {
343+
it("generates a PKCE challenge and returns the AuthKit URL", async () => {
345344
const { scope } = nockRefresh();
346345
expect(sessionStorage.getItem(storageKeys.codeVerifier)).toBeNull();
347346

@@ -368,7 +367,6 @@ describe("create-client", () => {
368367
provider: "authkit",
369368
redirect_uri: "https://example.com/",
370369
response_type: "code",
371-
screen_hint: "sign-in",
372370
},
373371
});
374372
expect(sessionStorage.getItem(storageKeys.codeVerifier)).toBeDefined();

src/create-client.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface RedirectOptions {
3030
organizationId?: string;
3131
passwordResetToken?: string;
3232
state?: any;
33-
type: "sign-in" | "sign-up";
33+
screenHint?: "sign-in" | "sign-up";
3434
}
3535

3636
type State =
@@ -116,23 +116,29 @@ export class Client {
116116
}
117117
}
118118

119-
async getSignInUrl(opts: Omit<RedirectOptions, "type"> = {}) {
120-
const url = await this.#getAuthorizationUrl({ ...opts, type: "sign-in" });
119+
async getSignInUrl(opts: Omit<RedirectOptions, "screenHint"> = {}) {
120+
const url = await this.#getAuthorizationUrl({ ...opts });
121121
return url;
122122
}
123123

124-
async getSignUpUrl(opts: Omit<RedirectOptions, "type"> = {}) {
125-
const url = await this.#getAuthorizationUrl({ ...opts, type: "sign-up" });
124+
async getSignUpUrl(opts: Omit<RedirectOptions, "screenHint"> = {}) {
125+
const url = await this.#getAuthorizationUrl({
126+
...opts,
127+
screenHint: "sign-up",
128+
});
126129
return url;
127130
}
128131

129-
async signIn(opts: Omit<RedirectOptions, "type"> = {}) {
130-
const url = await this.#getAuthorizationUrl({ ...opts, type: "sign-in" });
132+
async signIn(opts: Omit<RedirectOptions, "screenHint"> = {}) {
133+
const url = await this.#getAuthorizationUrl({ ...opts });
131134
window.location.assign(url);
132135
}
133136

134-
async signUp(opts: Omit<RedirectOptions, "type"> = {}) {
135-
const url = await this.#getAuthorizationUrl({ ...opts, type: "sign-up" });
137+
async signUp(opts: Omit<RedirectOptions, "screenHint"> = {}) {
138+
const url = await this.#getAuthorizationUrl({
139+
...opts,
140+
screenHint: "sign-up",
141+
});
136142
window.location.assign(url);
137143
}
138144

@@ -433,7 +439,7 @@ An authorization_code was supplied for a login which did not originate at the ap
433439
organizationId,
434440
passwordResetToken,
435441
state,
436-
type,
442+
screenHint,
437443
}: RedirectOptions) {
438444
const { codeVerifier, codeChallenge } = await createPkceChallenge();
439445
// store the code verifier in session storage for later use (after the redirect back from authkit)
@@ -447,7 +453,7 @@ An authorization_code was supplied for a login which did not originate at the ap
447453
organizationId,
448454
passwordResetToken,
449455
redirectUri: this.#redirectUri,
450-
screenHint: type,
456+
screenHint,
451457
state: state ? JSON.stringify(state) : undefined,
452458
});
453459

0 commit comments

Comments
 (0)