| 1 | "use client"; |
| 2 | |
| 3 | import type { AuthView } |
| 4 | import { useAuth } |
| 5 | import type { ComponentType |
| 6 | |
| 7 | import { AuthRedirect } |
| 8 | import { AuthCallback, AuthError |
| 9 | import { ForgotPassword } |
| 10 | import { ResetLinkSent } |
| 11 | import { ResetPassword } |
| 12 | import { SignOut } |
| 13 | import { SignUp } |
| 14 | import { VerifyEmail } |
| 15 | |
| 16 | // signIn has no entry: the username plugin always supplies it. |
| 17 | const AUTH_VIEWS: Partial |
| 18 | callback: AuthCallback, |
| 19 | error: AuthError, |
| 20 | redirect: AuthRedirect, |
| 21 | signOut: SignOut, |
| 22 | signUp: SignUp, |
| 23 | forgotPassword: ForgotPassword, |
| 24 | resetPassword: ResetPassword, |
| 25 | resetLinkSent: ResetLinkSent, |
| 26 | verifyEmail: VerifyEmail, |
| 27 | }; |
| 28 | |
| 29 | /** Renders the authentication view at `path`, preferring a plugin's view over the built-in one. */ |
| 30 | export function Auth({ |
| 31 | const { plugins, |
| 32 | |
| 33 | const authView = |
| 34 | (key) => |
| 35 | ); |
| 36 | |
| 37 | for (const plugin |
| 38 | const pluginAuthPaths = |
| 39 | const pluginView = |
| 40 | authView ?? |
| 41 | (pluginAuthPaths && |
| 42 | Object.keys(pluginAuthPaths |
| 43 | (key) => |
| 44 | )); |
| 45 | const PluginView = |
| 46 | if (PluginView) return |
| 47 | } |
| 48 | |
| 49 | const AuthView = |
| 50 | if (!AuthView) |
| 51 | throw new Error( |
| 52 | `Unknown auth view "${authView ?? |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return <AuthView /> |
| 57 | } |