Skip to content

Commit 53baf6d

Browse files
authored
feat(ts): strongly type sign-in and error page errors (#3740)
* feat: added types for sign in errors * feat: adding type to error prop * chore: added documentation links to types
1 parent 255c822 commit 53baf6d

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

src/core/pages/error.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { Theme } from "../.."
22
import { InternalUrl } from "../../lib/parse-url"
33

4+
/**
5+
* The following errors are passed as error query parameters to the default or overridden error page.
6+
*
7+
* [Documentation](https://next-auth.js.org/configuration/pages#error-page) */
8+
export type ErrorType =
9+
| "default"
10+
| "configuration"
11+
| "accessdenied"
12+
| "verification"
13+
414
export interface ErrorProps {
515
url?: InternalUrl
616
theme?: Theme
7-
error?: string
17+
error?: ErrorType
818
}
919

1020
interface ErrorView {
@@ -14,12 +24,6 @@ interface ErrorView {
1424
signin?: JSX.Element
1525
}
1626

17-
export type ErrorType =
18-
| "default"
19-
| "configuration"
20-
| "accessdenied"
21-
| "verification"
22-
2327
/** Renders an error page. */
2428
export default function ErrorPage(props: ErrorProps) {
2529
const { url, error = "default", theme } = props
@@ -87,15 +91,17 @@ export default function ErrorPage(props: ErrorProps) {
8791
status,
8892
html: (
8993
<div className="error">
90-
{ theme?.brandColor && <style
91-
dangerouslySetInnerHTML={{
92-
__html: `
94+
{theme?.brandColor && (
95+
<style
96+
dangerouslySetInnerHTML={{
97+
__html: `
9398
:root {
9499
--brand-color: ${theme?.brandColor}
95100
}
96101
`,
97-
}}
98-
/> }
102+
}}
103+
/>
104+
)}
99105
{theme?.logo && <img src={theme.logo} alt="Logo" className="logo" />}
100106
<div className="card">
101107
<h1>{heading}</h1>

src/core/pages/signin.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import { Theme } from "../.."
22
import { InternalProvider } from "../../lib/types"
33

4+
/**
5+
* The following errors are passed as error query parameters to the default or overridden sign-in page.
6+
*
7+
* [Documentation](https://next-auth.js.org/configuration/pages#sign-in-page) */
8+
export type SignInErrorTypes =
9+
| "Signin"
10+
| "OAuthSignin"
11+
| "OAuthCallback"
12+
| "OAuthCreateAccount"
13+
| "EmailCreateAccount"
14+
| "Callback"
15+
| "OAuthAccountNotLinked"
16+
| "EmailSignin"
17+
| "CredentialsSignin"
18+
| "SessionRequired"
19+
| "default"
20+
421
export interface SignInServerPageParams {
522
csrfToken: string
623
providers: InternalProvider[]
724
callbackUrl: string
825
email: string
9-
error: string
26+
error: SignInErrorTypes
1027
theme: Theme
1128
}
1229

@@ -39,7 +56,7 @@ export default function SigninPage(props: SignInServerPageParams) {
3956
)
4057
}
4158

42-
const errors: Record<string, string> = {
59+
const errors: Record<SignInErrorTypes, string> = {
4360
Signin: "Try signing in with a different account.",
4461
OAuthSignin: "Try signing in with a different account.",
4562
OAuthCallback: "Try signing in with a different account.",
@@ -59,16 +76,17 @@ export default function SigninPage(props: SignInServerPageParams) {
5976

6077
return (
6178
<div className="signin">
62-
63-
{ theme.brandColor && <style
64-
dangerouslySetInnerHTML={{
65-
__html: `
79+
{theme.brandColor && (
80+
<style
81+
dangerouslySetInnerHTML={{
82+
__html: `
6683
:root {
6784
--brand-color: ${theme.brandColor}
6885
}
6986
`,
70-
}}
71-
/> }
87+
}}
88+
/>
89+
)}
7290
{theme.logo && <img src={theme.logo} alt="Logo" className="logo" />}
7391
<div className="card">
7492
{error && (

0 commit comments

Comments
 (0)