@stormycms/next
Next.js authentication and session helpers.
pnpm add @stormycms/nextcreateNextAuthHandlers
Mount at app/api/auth/stormy/route.ts:
import { createNextAuthHandlers } from '@stormycms/next';
export const { GET, POST } = createNextAuthHandlers();createNextAuthHandlers(configOrClient?, options?) accepts partial client configuration, a StormyCMSClient, or environment defaults.
GET requests use the action query parameter:
| Action | Response |
|---|---|
signin | OAuth redirect. Requires provider; optional redirectTo sets the return destination. |
session | Session user JSON or 401. Refreshes the browser session cookie on success. |
site | Current site JSON |
sites | Accessible sites JSON |
signout | Clears the session cookie and redirects to /login |
| Absent | Exchanges the callback's token, sets the session cookie, and redirects to the saved destination or site URL |
GitHub and Google are available for sign-in. POST returns a placeholder response.
Session cookie
stormy_session_token is httpOnly, SameSite=lax, scoped to /, and secure in production. Its default browser lifetime is eight hours.
options.sessionCookieMaxAgeSeconds overrides STORMY_SESSION_COOKIE_MAX_AGE_SECONDS. Successful session calls refresh the cookie. API session expiry still applies.
StormyServerProvider
Loads the session and site data, then supplies client context. With guard: true, the default, it redirects unauthenticated users to loginUrl.
import { StormyServerProvider } from '@stormycms/next';import { stormyCMSClient } from '~/stormy-cms-client';
export default function DashboardLayout({ children }: { children: React.ReactNode }) { return ( <StormyServerProvider client={stormyCMSClient} loginUrl="/login"> {children} </StormyServerProvider> );}Place it in a protected route layout so /login remains accessible. Other props are authUrl, siteUrl, sitesUrl, checkThrottleMs, and onSessionExpired, as described in the React reference.
Authenticate writes in your server actions and route handlers too. A layout redirect does not authorize those requests.
createServerActions
createServerActions(client) returns signIn(provider?, options?) and signUp(provider?, options?). Both accept redirectTo and authUrl options.
Export async server actions:
'use server';
import { createServerActions } from '@stormycms/next';import { stormyCMSClient } from '~/stormy-cms-client';
export async function signInWithGitHub() { await createServerActions(stormyCMSClient).signIn('github', { redirectTo: '/pages' });}Last updated: 10/20/26, 1:09 AM