This page uses Next.js (App Router, src/app) with the drop-in sign-in UI. Other frameworks are in JavaScript.
The JavaScript packages are prereleases published under the next npm tag. Install them with @next.
Create an app#
Create an account and a workspace
Sign in at control.scute.io with your email. A first sign-in creates your account. The dashboard then asks for a workspace name and slug. You are the workspace's owner.
Create an app
In the New app flow, enter the site where people sign in. For local development enter localhost:3000, which becomes the origin http://localhost:3000. The name is taken from the site and can be changed later.
When the app is created, the dashboard shows its App ID (app_...). It is also on the app's Overview page.
Add sign-in to Next.js#
Install the packages
Terminalbashnpm install @scute/nextjs-handlers@next @scute/react-hooks@next @scute/auth-ui-react@nextSet the App ID
.env.localbashNEXT_PUBLIC_SCUTE_APP_ID=app_xxx@scute/nextjs-handlers reads NEXT_PUBLIC_SCUTE_APP_ID itself.
Add the route handler
One catch-all route serves the session endpoints and keeps the refresh token in an httpOnly cookie.
src/app/auth/[...scute]/route.tstsimport { cookies, headers } from "next/headers";import { ScuteHandler } from "@scute/nextjs-handlers";const handler = ScuteHandler({ cookies, headers });export { handler as GET, handler as POST };Add the providers
ScuteAuthGate shows the sign-in form until the visitor is signed in, then renders its children.
src/app/scute-providers.tsxtsx"use client";import { useState } from "react";import { createClientComponentClient } from "@scute/nextjs-handlers";import { AuthContextProvider } from "@scute/react-hooks";import { ScuteAuthGate } from "@scute/auth-ui-react";export function ScuteProviders({ children }: { children: React.ReactNode }) { // Reads NEXT_PUBLIC_SCUTE_APP_ID itself. const [client] = useState(() => createClientComponentClient()); return ( <AuthContextProvider scuteClient={client}> <ScuteAuthGate>{children}</ScuteAuthGate> </AuthContextProvider> );}Wrap the root layout
src/app/layout.tsxtsximport { ScuteProviders } from "./scute-providers";export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> <ScuteProviders>{children}</ScuteProviders> </body> </html> );}Run the app and open http://localhost:3000. The sign-in form asks for an email. A new email creates a user, an existing one signs in. The method (passkey, magic link or code) follows the app's settings in the dashboard. See Authentication methods.
Read the user on the server
createServerComponentClient reads the session cookies the browser client wrote and asks Scute who they belong to. It never refreshes a token: the browser client does that.
src/lib/session.tstsimport { cookies } from "next/headers";import { createServerComponentClient } from "@scute/nextjs-handlers";export async function getSignedInUser() { const cookieStore = await cookies(); const scute = createServerComponentClient({ cookies: () => cookieStore }); const { data, error } = await scute.getUser(); if (error || !data?.user) return null; return data.user;}
Verify the token on your server#
A separate backend receives the access token from the browser and verifies it offline with the app's JWKS (RS256). In the browser, read the token with getAuthToken() and send it as a bearer token:
import { useScuteClient } from "@scute/react-hooks";// Inside a component:const scute = useScuteClient();const { data } = await scute.getAuthToken();await fetch("https://your-api.example.com/me", { headers: { Authorization: `Bearer ${data?.access}` },});On the server, verify it. The Python and Ruby SDKs fetch and cache the keys, check the signature, the expiry and that the token belongs to your app (aid). They need only SCUTE_APP_ID.
# pip install git+https://github.com/scuteai/scute-pythonfrom scute import Scute, InvalidTokenscute = Scute() # reads SCUTE_APP_IDdef current_user_id(authorization: str | None) -> str | None: token = (authorization or "").removeprefix("Bearer ") try: return scute.tokens.verify(token).user_id except InvalidToken: return NoneOffline verification does not see a session revoked a moment ago. Where that matters, call scute.tokens.verify(token, remote=True) in Python or scute.tokens.verify(token, remote: true) in Ruby, which also asks Scute.
Next steps#
- Concepts: apps, users, sessions and keys.
- MFA: turn on a second factor.
- Authorization: roles and permission checks.
- JavaScript, Python, Ruby: the full SDK references.