netlify/context-and-tools/netlify-identity
Claude Code and agent skill by netlify/context-and-tools
- community
- ext:[{"type":"template","description":"Custom templates for code generation"}]
Checking that the SKILL.md file is still in the repository.
Add user authentication to a Netlify site with @netlify/identity — signup/login/logout, Google/GitHub/GitLab/Bitbucket OAuth, server-side getUser() checks, role-based access control, and Identity event functions. Use it when a task involves adding a login or signup form, gating content to members or roles, "auth middleware" or verifying users in Netlify Functions or Edge Functions, handling OAuth or email-confirmation callbacks, assigning roles at signup, or customizing Identity emails. For loc…
Install
npx vskill@latest install netlify/context-and-tools/netlify-identitySemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Netlify Identity
Use @netlify/identity (npm). For new projects it replaces the legacy netlify-identity-widget and gotrue-js. Do not reach for those.
Framework examples (Next.js/Astro/Remix/SvelteKit) and the full API reference are in the `@netlify/identity` README on npm.
Identity does not run under `netlify dev`. Test all auth flows on a deploy. Deploy Previews work. Local dev will not complete signup/login/OAuth.
Identity config is dashboard-only. There is no public API. Never curlapi.netlify.comto flip or read Identity settings, never read tokens from local Netlify config, and never probe undocumented endpoints. Enable and configure Identity athttps://app.netlify.com/projects/{site_name}/identity.
Never build a from-scratch OAuth flow alongside Identity. No provider app registration in code, noclient_id/secretin source, and no custom callback token exchange. UseoauthLogin()+handleAuthCallback(). Raw OAuth beside Identity is the most common source of rework.
Client auth (browser)
`handleAuthCallback()` is mandatory on your landing page. Without it, OAuth redirects, email-confirmation links, password-recovery links, and invite links never complete. Call it on page load.
Invites are NOT logged in by `handleAuthCallback()`. For an invite it returnstype === 'invite'with the token inresult.tokenandresult.user === null. The account does not exist yet. You must collect a password and callacceptInvite(result.token, password). If you skip this step, invited users never get an account.
For recovery tokens you can call recoverPassword() directly instead. Refresh a session with refreshSession().
Don't hard-code which providers exist. Call getSettings() at startup and render the signup form and OAuth buttons from what it returns.
Server-side auth (Netlify Functions & Edge Functions)
Server-side getUser()/login()/admin.* require modern v2 functions (export default). The v1 export { handler } form is not supported.
getUser() works in both runtimes. `admin.*` runs ONLY in Netlify Functions. It does not run in the browser or in Edge Functions.
The Edge Function form is identical but imports Context from @netlify/edge-functions.
Role checks
CSRF: required for server-side auth endpoints
Any endpoint that runslogin(),signup(), orlogout()server-side must callverifyRequestOrigin(req)at the top of the handler. It throws a 403 on origin mismatch.
Identity event functions
The platform calls your handler when an Identity event occurs. Export a default object with a method per event. File: netlify/functions/identity.mts.
Typed handlers (UserSignupEvent,event.deny()) require@netlify/functions≥ 5.2.0. Older installs must use the legacy filename convention (identity-signup.ts, etc.). Seereferences/authorization-and-sessions.md.
| Handler | Fires when | |
|---|---|---|
userValidate | Signup attempt, before account creation. Block bad signups here. | |
userSignup | Signup completes (after email confirmation if enabled). Assign roles, sync, welcome. | |
userLogin | User logs in. Track/last-seen/block. | |
userModified | Profile updated. | |
userDeleted | User deleted (notification only). |
Event user fields are camelCase (appMetadata, userMetadata, confirmedAt).
event.deny()rejects the action. The end user gets a401, and no error appears in observability. The first handler to call it aborts the chain, and later subscribers are not invoked. Legacy filename functions signal denial with a non-2xxResponseinstead.- Return
{ user: {...} }to modify the record before it is persisted. This is the canonical way to set roles at signup. Roles ride in the JWT, so a role change takes effect on the user's next login or token refresh, not immediately. See Roles & the JWT below. - Background mode:
export const config: Config = { background: true }. The action completes immediately and the handler runs asynchronously.
Roles & the JWT
user.rolesis read fromapp_metadata.rolesand carried in the JWT (cookienf_jwt; refresh vianf_refresh).user_metadataholds the user-editable profile (full_name,email).app_metadataholds app data, includingroles, and is not user-editable.
Role changes are NOT immediate. They take effect on next login or token refresh. Changing roles does not invalidate the current JWT. Force a refresh withrefreshSession().
Set roles for existing users via admin.updateUser() in a Netlify Function. Set them at signup via the userSignup event handler above.
Deep guides for SSR/session hydration and authorization live in references/advanced-patterns.md and references/authorization-and-sessions.md.
CDN-edge RBAC (redirect rules)
Enforced at the edge with no origin round trip. A mismatched role gets a 404 unless you add a fallback. Always pair a role-gated rule with a fallback.
_redirects:
netlify.toml:
Use redirect rules for path-based gating. Use function-based user.roles checks for custom authorization logic.
Configuration (dashboard-only)
Base: https://app.netlify.com/projects/{site_name}/identity. Enable with Enable Identity. Identity requires HTTPS, so set up SSL before integrating on a custom domain.
- Registration (
?tab=registration#registration-preferences): Open (default; anyone can sign up) or Invite only (all users, including external-provider logins, must be invited first). - Confirmation / autoconfirm (
?tab=emails#confirmation-template): check the box to skip email verification. - External providers (
?tab=registration#external-providers): Google/GitHub/GitLab/Bitbucket. For branded OAuth (your app name instead of "Netlify Identity"), register your app with the provider, get a client ID and secret, and enter them in the Netlify settings UI, not in code. - Invitations (
?tab=users): enter addresses to send invites. The link carriesinvite_token. Complete it withhandleAuthCallback()+acceptInvite(token, password)as shown above. - Password recovery: on the user page, use Send reset password email. The link carries
recovery_token.
Emails (Pro plans or higher)
The default sender is no-reply@netlify.com. A custom SMTP sender and custom templates both require Pro plans or higher.
Template variables (Go syntax): {{ .Email }}, {{ .NewEmail }} (email-change only), {{ .SiteURL }}, {{ .ConfirmationURL }}, {{ .Token }}.
Custom-link hash fragments per action:
Custom template constraints:
- Inline CSS only.
- Absolute image links.
- No `<html>`/`<head>`/`<body>` tags.
- Ensure your build doesn't alter Go template variables.
Audit log (Pro plans or higher)
?tab=audit-log. Search with a scoped term: author:[string] or action:[string].
Action names: login, logout, user_signedup, user_deleted, user_modified, token_revoked, token_refreshed, user_recovery_requested, user_invited.
External JWT providers (Enterprise)
Available on Enterprise plans. You may use Netlify Identity OR an external JWT provider, not both at once. You cannot authenticate third-party JWTs while Netlify Identity is enabled.
- Roles path: Netlify Identity uses
app_metadata.roles; an external provider usesapp_metadata.authorization.roles. For a custom path, contact support. - The JWT header must be
{"alg": "HS256", "typ": "JWT"}(HS256 required). The payloadexpis required and must be a future Unix Epoch time. - Set the JWT secret at
Project configuration > General > Visitor access > JWT secret. Project-level settings override team-level defaults.
On failure — stop, don't guess
If callbacks 404, /.netlify/identity/* is unreachable, or an OAuth flow never returns:
- Surface the error.
- Give the dashboard URL (
https://app.netlify.com/projects/{site_name}/identity). - Name the setting to check (registration preference, external provider config, confirmation/autoconfirm).
- Then stop. Do not invent recovery commands.
Remember: Identity does not work under netlify dev. Confirm you are testing on a deploy.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/netlify-identity/SKILL.md
Popularity
- Repository stars
- 48
- Repository forks
- 14
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
templateCustom templates for code generation
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/netlify/context-and-tools/netlify-identity)