This skill gives the person a Next.js app wired to their Drupal backend for sign-in. The backend is a site made by the backend-setup skill.
Before you start
- Run the machine-check skill first:
bash scripts/check-machine.shin that skill. Go on only when its JSON saysreadyis true. Otherwise, show the person what it reports and stop. - Node 22.13 or later and
mkcertmust be installed. The script checks both. - The backend must be running, and it must carry the Simple OAuth client
nextjswith redirect URIhttp://localhost:3000/api/auth/callback. A backend made by backend-setup at its default template ref has it. - Propose an app folder beside the backend folder, for example
<backend-folder>-app. It must not exist yet, or must be empty. Tell the person the path and wait for their agreement before you run the script.
Create the app
Run this skill's script with absolute paths:
bash <this-skill-folder>/scripts/setup-frontend.sh --backend <backend-project-folder> <app-folder>
The script does these steps in order:
- It checks Node, npm, mkcert and that the backend answers.
- It runs
create-next-app@16.4.1with explicit flags (TypeScript, App Router, ESLint, Tailwind, nosrc/, npm). Next.js 16.4.1 is the security floor. - It copies this skill's
assets/appfolder over the new app. - It installs
openid-clientandiron-sessionat exact versions. - It sets the
devscript sonpm run devexportsNODE_EXTRA_CA_CERTSfrommkcert -CAROOTbeforenext dev. Node rejects DDEV's mkcert certificate without it and reads the variable only at launch. npm runs scripts throughsh, so this does not work under plain Windows cmd. - It writes
.env.localonce, withDRUPAL_BASE_URL,DRUPAL_CLIENT_ID,DRUPAL_SCOPE,APP_URLand a randomSESSION_SECRET. - It stops unless git confirms
.env.localis ignored. - It prints
App folder:,Backend URL:and the start command. Give them to the person.
No Drupal host sits in the app's source. To point the app at another backend, edit DRUPAL_BASE_URL in .env.local only.
Running the script again on an app it made skips create-next-app and the install, copies the app files over the app again, and never touches .env.local.
Sign-in and logout
Sign-in uses Drupal's own login form. Logout drops the tokens from the app's session and then sends the person to Drupal's logout page, which asks for one confirm click. That ends the Drupal login.
In code you write for the app, signed in means the session holds an access token, never just a name. Use isSignedIn in lib/auth-state.ts.
Token refresh is safe within one server process only, such as npm run dev or a single next start; with several processes or serverless instances, two refreshes at once can sign the person out.
Simple OAuth has no revoke endpoint, so a token already issued stays valid for up to 300 seconds after logout, and a refresh token until its lifetime ends. Tell the person this if they ask how final a logout is.
When a step fails
After you fix the cause, run the script again on the same folder.
- Node is older than 22.13: install a newer Node through the machine-check skill's advice.
- The backend did not answer: run
ddev startin the backend folder. - The folder exists and is not empty: pick another folder, or ask the person.
create-next-appornpm installfails: show the person the output. A partly made app folder is not a valid rerun target untilpackage.jsonlistsopenid-client; remove it with the person's agreement and run again..env.localis not ignored by git: add.env.localto the app's.gitignore, then run again.