Next.js (App Router)
Complete references for Next.js App router SDK
Quickstart
Visit Next.js app router's quickstart page.
References
<CakeAuthProvider />
Component CakeAuthProvider
is required to integrate CakeAuth in a React platform. This provider provides contexts and data that being used by various hooks and/or components.
Usage
Properties
Prop | Type | Default |
---|---|---|
children | React.ReactNode | - |
config.publicKey | string | - |
config.url | string? | Decoded from the public key |
config.pages.signin | string? | / |
config.pages.signup | string? | /?flow=signup |
config.pages.passwordReset | string? | /?flow=password_reset |
<SignIn />
Component SignIn
is rendering a page of signin screen.
Usage
Properties
Prop | Type | Default |
---|
<SignInCard />
Component SignInCard
is rendering a sign in card component (not a whole page like <SignIn />
)
Usage
Properties
Prop | Type | Default |
---|
<SignUp />
Component SignUp
is rendering a page of signup screen.
Usage
Properties
Prop | Type | Default |
---|
<SignUpCard />
Component SignUpCard
is rendering a sign up card component (not a whole page like <SignUp />
)
Usage
Properties
Prop | Type | Default |
---|
<PasswordReset />
Component PasswordReset
is rendering a page of password reset flow.
Usage
Properties
Prop | Type | Default |
---|
<PasswordResetCard />
Component PasswordResetCard
is rendering a sign up card component (not a whole page like <PasswordReset />
).
This component has two main logic:
- Forms to create a new password reset attempt
- Forms to input new password (if the valid password reset query is available)
Usage
Properties
Prop | Type | Default |
---|
<Captcha />
The Captcha
component, requires the bot protection settings to be configured. Under the hood, it uses:
react-turnstile
: for Cloudflare Turnstile supportreact-google-recaptcha
: for Google reCAPTCHA support
Usage
Properties
Prop | Type | Default |
---|---|---|
type | turnstile | recaptcha | null | undefined | - |
siteKey | string | - |
onVerify() | (token: string) => void | - |
<SignedIn />
The SignedIn
component is a wrapper component that will only renders the children if there's a User with an active Session signed in your application.
Usage
Properties
Prop | Type | Default |
---|---|---|
children | React.ReactNode | - |
<SignedOut />
The SignedOut
component is a wrapper component that will only renders the children if there's no User with an active Session signed in your application.
Usage
Properties
Prop | Type | Default |
---|---|---|
children | React.ReactNode | - |
<UserButton />
The UserButton
component renders a button which on click displays a dropdown of common quick actions that current users can do. Such as:
- Manage Account (which renders the
<UserDialog />
) - Signin out
Usage
Properties
Prop | Type | Default |
---|---|---|
align | center | end | start | undefined | center |
className | string | - |
<UserDialog />
The UserDialog
component renders a featured users management dialog that allows users to manage their account and sessions.
Currently, users can:
- See their details
- Reset password (if current identifier
is_password_enabled=true
) - List their active sessions and revoke a session
- Signing out (revoking current session)
Usage
Properties
Prop | Type | Default |
---|---|---|
open | boolean | - |
onOpenChange() | (open: boolean) => void | - |
<CakeAuthLoaded />
The CakeAuthLoaded
component is a wrapper component that will only renders the children when the CakeAuth data has loaded.
Usage
Properties
Prop | Type | Default |
---|---|---|
children | React.ReactNode | - |
<CakeAuthLoading />
The CakeAuthLoading
component is a wrapper component that will only renders the children when the CakeAuth data is still loading.
Usage
Properties
Prop | Type | Default |
---|---|---|
children | React.ReactNode | - |
createRouteMatcher
A utility function for creating route matchers to handle matching your pathname.
Usage
Properties
Prop | Type | Default |
---|---|---|
patterns | string[] | - |
Returns
Prop | Type | Default |
---|---|---|
(path: string) => boolean | (path: string) => boolean | - |
cakeauthMiddleware
Middleware function to handle authentication and route protection in Next.js applications.
Use:
auth.protect()
: to automatically redirects to signin page if no valid auth credentials foundauth.isAuthenticated
: to check whether current auth credentials valid
Usage
- Base usage:
- Usage with
createRouteMatcher
to protect paths
Types
Properties
Prop | Type | Default |
---|---|---|
handler | handler?: (auth: Auth, request: Request) => Promise<NextResponse<unknown> | undefined> | - |
getOAuthUrl
Function to generate OAuth URLs for various providers. Returns a URL string or null if required parameters are missing.
Usage
Properties
Prop | Type | Default |
---|---|---|
provider | github | google | - |
clientId | string | null | undefined | - |
redirectUri | string | null | undefined | - |
scopes | string[] | - |
publicKey | string | - |
Returns
string | null
- The generated OAuth URL or null if required parameters are missing.
useHandshakeExchange
Hook for handling the OAuth handshake exchange process. Read more about handshake exchange process here.
Usage
Properties
Prop | Type | Default |
---|---|---|
cakeauth | CakeAuth | - |
Returns
Prop | Type | Default |
---|---|---|
state | State | - |
error | CakeAuthErrorResponse | null | - |
useRefreshAccessToken
Hook for refreshing the access token. Can only being invoked if a valid user sessions is present. Read more about CakAuth refresh token mechanism and process here.
Usage
Properties
Prop | Type | Default |
---|---|---|
cakeauth | CakeAuth | - |
Returns
Prop | Type | Default |
---|---|---|
state | State | - |
error | CakeAuthErrorResponse | null | - |
useSession
React hook that provides authentication session state and data.
Usage
Returns
Prop | Type | Default |
---|---|---|
isAuthenticated | boolean | - |
state | State | - |
error | Error | null | - |
value.sessionId | string | - |
value.userId | string | - |
value.accessToken | string | - |
useSettings
Hook for getting current environment [settings details](/frontend#tag/settings/GET/v1/settings.
Usage
Types
Returns
Prop | Type | Default |
---|---|---|
value | GetSettingsResponse | null | - |
state | State | - |
error | CakeAuthErrorResponse | null | - |
useSignout
Hook for handling user sign out.
Usage
Returns
Prop | Type | Default |
---|---|---|
state | State | - |
error | CakeAuthErrorResponse | null | - |
signout() | () => Promise<void> | - |
useUser
Hook for accessing the current user data.
Usage
Types
Returns
Prop | Type | Default |
---|---|---|
state | State | - |
error | CakeAuthErrorResponse | null | - |
value | GetMeResponseItem | null | - |
I'll create documentation for both OAuth URL generator functions.
getGithubOAuthUrl
Function to generate GitHub OAuth URLs with required state parameters.
Usage
Properties
Prop | Type | Default |
---|---|---|
clientId | string | - |
redirectUri | string | - |
scope | string[] | - |
config.origin | string | - |
config.csrf_token | string | - |
config.provider | "github" | - |
config.user_agent | string | - |
config.public_key | string | - |
Returns
string
- The generated GitHub OAuth URL
getGoogleOAuthUrl
Function to generate Google OAuth URLs with required state parameters.
Usage
Properties
Prop | Type | Default |
---|---|---|
clientId | string | - |
redirectUri | string | - |
scope | string[] | - |
config.origin | string | - |
config.csrf_token | string | - |
config.provider | "github" | - |
config.user_agent | string | - |
config.public_key | string | - |
Returns
string
- The generated Google OAuth URL
redirectTo
Utility function for handling redirects in the application. A thin wrapper to the web Response interface.
Usage
Parameters
Prop | Type | Default |
---|---|---|
path | string | - |
Last updated on