@scute/js-core has no UI. You build the form and call the client. The same package runs on a Node server to check who sent a request.
Install#
npm install @scute/js-core@nextBrowser#
src/sign-in.jsjs
import { createClient } from "@scute/js-core";const scute = createClient({ appId: import.meta.env.VITE_SCUTE_APP_ID });// Back from the email link (sct_magic) or from Google or SAML (sct_oauth).if (scute.getMagicLinkToken()) { const { data, error } = await scute.signInWithMagicLink(); if (error) console.error(error.message); else if (data) console.log("The sign-in needs another step:", data);}document.querySelector("#sign-in").addEventListener("submit", async (e) => { e.preventDefault(); const email = new FormData(e.currentTarget).get("email"); // A passkey, or an email link or code, as the app is set up. const { data, error } = await scute.signInOrUp(email); if (error) return alert(error.message); if (data?.magic_link) showMessage("Check your email for the sign-in link."); if (data?.otp) showCodeForm(email);});async function submitCode(code, email) { const { data, error } = await scute.verifyOtp(code, email); if (error) return alert(error.message); if (data.authPayload) await scute.signInWithTokenPayload(data.authPayload);}scute.onAuthStateChange((event, session, user) => { if (event === "signed_in") console.log("Signed in as", user.email);});showMessage and showCodeForm are your own UI. What signInOrUp returns depends on the app's settings:
| data | Meaning | Next |
|---|---|---|
| { magic_link: { id } } | A sign-in link was sent. | Wait for the link, or poll its status on this device. See Magic links. |
| { otp: { id } } | A code was sent by email or SMS. | verifyOtp(code, identifier). See One-time codes. |
| null | A passkey signed the user in. | Nothing. signed_in fires. |
| { mfaRequired: true, ... } or { contactVerificationRequired: true, ... } | The sign-in needs another step. | See MFA. |
Node server#
The browser sends the session's access token as a bearer token. The server asks Scute who it belongs to.
scute-auth.jsjs
import { createClient } from "@scute/js-core";export const scute = createClient({ appId: process.env.SCUTE_APP_ID });// The signed-in person for a request, or null.export async function currentUser(req) { const token = req.headers.authorization?.replace(/^Bearer /, ""); if (!token) return null; const { data, error } = await scute.getUser(token); return error ? null : data.user;}Call currentUser(req) in any route (Express, Fastify, node:http). null means signed out. Calls that manage users or check permissions also need the secret key; see Admin API.
Next steps#
Client setup
Options, storage and defaults.
Sign in
signInOrUp, signIn and signUp in detail.
Events
Every event onAuthStateChange delivers.