@autional/next
v0.2.1
Published
AuthMS Next.js SDK — middleware, server session, and provider for Next.js App Router
Downloads
274
Maintainers
Readme
@authms/next
AuthMS Next.js SDK — middleware, server-side session, and provider for Next.js App Router.
What's Inside
authmsMiddleware— edge middleware that redirects unauthenticated users from protected pathsgetServerSession— server-side session lookup via cookie token +/auth/meAPI callAuthmsProvider— client component wrapper (re-exports from@authms/reactwith SSR support)
Install
npm install @authms/core @authms/react @authms/nextQuick Start
// middleware.ts
import { authmsMiddleware } from '@authms/next';
export const config = { matcher: ['/dashboard/:path*', '/settings/:path*'] };
export default authmsMiddleware({
protectedPaths: ['/dashboard/(.*)', '/settings/(.*)'],
loginPath: '/login',
publicPaths: ['/'],
});// app/layout.tsx
import { AuthmsProvider } from '@authms/next';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<AuthmsProvider appId="my-app" issuer="https://auth.iam.tianv.com">
{children}
</AuthmsProvider>
</body>
</html>
);
}// app/dashboard/page.tsx
import { getServerSession } from '@authms/next';
export default async function DashboardPage() {
const session = await getServerSession({ authUrl: 'https://auth.iam.tianv.com' });
if (!session.user) return <div>Not authenticated</div>;
return <h1>Welcome, {session.user.displayName}</h1>;
}Project Setup
Copy examples/next-authms.ts to src/authms.ts, edit appId and issuer. All your components import from ./authms.
See the root SDK README for full documentation.
