Skip to main content
The @gately/nextjs SDK provides production-ready authentication for Next.js applications with App Router, Server Components, and middleware support.
Version: @gately/nextjs@2.2.0
Features: useGately hook, GatelyProvider, server utilities, route middleware, SSR support

Installation

Or install a specific version:
Get your API key: Dashboard → Settings → API Keys

Quick Start

1. Create a Providers Component

Because GatelyProvider uses browser APIs, it must run client-side:

2. Add to Root Layout

3. Use in Client Components

4. Protect Pages with Middleware

GatelyProvider

useGately Hook

For use in 'use client' components:

Server Utilities

Use in Server Components, Route Handlers, and Server Actions:

getSession()

getUser()

isAuthenticated()

API Route Handler

Middleware

gatelyMiddleware

Supports two calling styles: Direct (recommended):
Factory:

MiddlewareConfig

Login Page

Environment Variables

TypeScript

Troubleshooting

GatelyProvider must be inside a 'use client' component. See the Providers setup above — never import it directly in a Server Component.
Ensure you’re on @gately/nextjs@1.0.2. Run:
Make sure your login page is in publicRoutes and not in protectedRoutes.

Next Steps

React SDK

Client-side hooks reference

Node.js SDK

Backend token verification
Support: support@usegately.com · Slack Community