This is week 5 of Build with CloudHike, a weekly series where we build a small, real-world app with an AI coding agent and let CloudHike handle the backend. New here? Week 1 built a referral waitlist, week 2 moved slow AI work into background jobs, week 3 built a file-sharing app with presigned uplo
ads, and week 4 connected every major AI editor to one project. Each post stands on its own, so you can start right here. Week 1 used Auth for exactly one person: you, on an admin page. That's the easy case.
The moment strangers can sign up, "login" turns into a list: confirm the email is real, let people reset a forgotten password, offer "Continue with GitHub" because nobody wants another password, keep the session token away from page scripts, and make sure every email link and OAuth redirect lands back on your site and nowhere else. Usually that list means an auth library, an SMTP provider, and two OAuth apps registered in two developer consoles. This week your agent deploys CloudHike Auth over MCP, you flip a few switches on the Auth page, and you build all of it with copy-paste prompts. Every endpoint, header and setting below comes from the live Auth docs and MCP docs.
A Next.js app called members-club with a private /members area: Email and password sign-up that requires a verified email before the first sign-in A "resend verification email" button for people who lost the first one Forgot password: a reset link by email, and a page to set a new password Continue with GitHub and Continue with Google, using CloudHike's shared OAuth app (no OAuth app of your own to register) HTTP-only cookie sessions: the token lives in a cookie your server sets, and server code checks it on every request Sites users can return to: every verification link, reset link and OAuth redirect only goes back to sites you listed An optional /admin page that lists members with the server-only secret key Here's how it maps to CloudHike, all in one project: Postgres 16 (DATABASE_URL). Deployed first, so Auth keeps its users in the project's own database, in the auth schema Auth (AUTH_URL, AUTH_PUBLISHABLE_KEY, AUTH_SECRET_KEY). A plain HTTP API for sign-up, sign-in, sessions, verification, resets and social sign-in Verification and reset emails sent by CloudHike's own sender, so there's no SMTP to configure A CloudHike account. Every new account gets $10 in free credits (eligible accounts, once per inbox, valid for 90 days), plus an extra $5 with the code TUBEGURUJI5, and no card is needed.
The Free plan allows 2 projects and up to 10,000 registered auth users per project, which is plenty for this. Cursor or Claude Code (Codex, VS Code, Windsurf and Gemini CLI work too; see week 4). Node.js, for a Next.js app. A GitHub and/or Google account to test social sign-in, and an inbox you can read for the verification and reset emails.
In the CloudHike dashboard, open Connect MCP in the sidebar (https://cloudhike.dev/dashboard/coding-agent), pick your editor and click Copy with key. That creates your workspace API key the first time and gives you a snippet with the key already filled in. The server is remote (Streamable HTTP), so there's nothing to install. Claude Code claude mcp add --transport http --scope user cloudhike https://cloudhike.dev/api/mcp \ --header "Authorization: Bearer icu_your_api_key" Run /mcp inside Claude Code to check that it's connected.
Cursor (~/.cursor/mcp.json) { "mcpServers": { "cloudhike": { "url": "https://cloudhike.dev/api/mcp", "headers": { "Authorization": "Bearer icu_your_api_key" } } } } Open Cursor Settings → MCP and look for the green dot. Snippets for Codex, VS Code, Windsurf, Gemini CLI and Claude Desktop are in the MCP docs. Treat the key like a password: keep it in your home folder, not the repo. Revoke on the Connect MCP page disconnects every editor at once. npx create-next-app@latest members-club cd members-club Open the folder in Cursor, or run claude in it. Paste: Use the cloudhike MCP tools to set up the backend for this app. It's a members-only Next.js app: people sign up, verify their email, and then see a private /members area. Create a CloudHike project called "members-club".
Deploy postgres first and wait until it's ready, then deploy auth and wait again, so Auth keeps its users in the project's Postgres. Put the .env into .env.local, make sure it's git-ignored, and don't show me any secret values. Then call get_docs for "auth" and summarise the endpoints and headers it describes. Don't write app code yet.
Tell me which services are running and which variable names are in .env.local. Behind the scenes that's create_project, deploy_services (twice), wait_for_services, get_environment written straight into .env.local, and get_docs for the Auth page as Markdown. You should end up with DATABASE_URL, AUTH_URL, AUTH_PUBLISHABLE_KEY and AUTH_SECRET_KEY. What those three Auth values are for, straight from the docs: AUTH_URL: the base address of your project's auth API.
Safe in browser code. AUTH_PUBLISHABLE_KEY: identifies your project, sent as the x-api-key header on every request. Safe in browser code. AUTH_SECRET_KEY: unlocks the admin endpoints.
Server only. Never ship it to a browser or mobile app. Provider and email settings live on the Auth page, not in MCP. Open the project, then Open Auth on the Auth card: Providers tab → Require a verified email before sign-in.
Turn it on. Sign-up now sends a verification link, and sign-in returns 403 until the user opens it. Sites users can return to. Add each site your app runs on, one per line: your local dev address now, your production domain later.
Verification links, reset links and social sign-in only ever send users back to these sites. Sign in with GitHub or Google. For each provider, pick the credential source Shared, which uses CloudHike's own OAuth app. Later you can switch to Your own and paste the client ID and secret of an OAuth app you registered, with the callback URL shown on the card (<AUTH_URL>/callback/github or /callback/google).
Emails tab (optional). Change the sender name, set a reply-to address, and edit the wording of the verification and password reset emails with a live preview and a test send. If you've verified a domain under Email → Domains, you can send from an address on it. That's the whole "auth provider setup".
No SMTP credentials, no OAuth console, no redirect URI juggling for the shared app. One detail from the docs shapes the whole design: the Auth API itself uses no cookies. Sign-up and sign-in return { token, user }, and you send the token as authorization: Bearer <token>. That's why it works from any site, a mobile app or a server.
For a web app, the docs recommend storing the token in an HTTP-only cookie that your own server sets, then calling get-session from server code on each request, which keeps the token away from page scripts. Paste: Using only what the auth page from get_docs describes, build email and password auth for this Next.js app, with all CloudHike calls in server code: lib/auth.ts: small helpers that call AUTH_URL with the header x-api-key set to AUTH_PUBLISHABLE_KEY: signUp (POST /sign-up/email with name, email, password), signIn (POST /sign-in/email with email, password), getSession (GET /get-session with authorization: Bearer ) and signOut (POST /sign-out with the same bearer header). Errors come back as { message } with a status code; pass the status and message through. Route handlers: POST /api/auth/sign-up, POST /api/auth/sign-in and POST /api/auth/sign-out. Sign-in stores the returned token in an HTTP-only cookie named "session" (Secure in production, SameSite=Lax, path /). Never return the token to page scripts. Sign-out calls /sign-out and deletes the cookie. Email verification is required, so sign-up must NOT set the cookie.
After a successful sign-up, send the user to /check-email. lib/current-user.ts: read the "session" cookie and call get-session from server code on every request. Return the user, or null when there's no cookie or the session is null. Pages: /sign-up (name, email, password, at least 8 characters), /sign-in, /check-email ("we sent you a link"), and /members, which redirects to /sign-in when there's no user and otherwise greets the user by name and email, with a sign-out button.
Do not import AUTH_SECRET_KEY anywhere in this step. Why server-side get-session on every request instead of trusting the cookie? Because sign-out, a deleted user, or an expired session are decided by Auth, not by the cookie. The check is one GET, and the answer is the session and user, or null.
With verification on, the first sign-in after sign-up returns 403. Turn that into a friendly screen: Handle unverified emails. When POST /sign-in/email returns 403, show "Please verify your email first" on /sign-in with a "Resend verification email" button. The button calls a new server route, POST /api/auth/resend-verification, which calls POST {AUTH_URL}/send-verification-email with { email, callbackURL } and the x-api-key header, where callbackURL is this site's origin + "/sign-in?verified=1".
On /sign-in, show "Email verified, you can sign in now" when verified=1 is in the URL. Add the same resend button to /check-email. Try it: sign up with a real inbox, try to sign in before clicking the link (403, friendly message), click the link, land back on your site, sign in, reach /members. The docs describe a two-call reset.
Paste: Add a forgotten-password flow following the "Email and password" section of the auth docs: /forgot-password: an email field that posts to POST /api/auth/forgot-password. That server route calls POST {AUTH_URL}/request-password-reset with { email, redirectTo } and the x-api-key header, where redirectTo is this site's origin + "/reset-password". Whatever happens, show the same message: "If that address has an account, a reset link is on its way." /reset-password: read token from the query string. Ask for the new password twice (at least 8 characters, must match) and post to POST /api/auth/reset-password, which calls POST {AUTH_URL}/reset-password with { newPassword, token } and the publishable key as x-api-key.
On success, redirect to /sign-in?reset=1 and show "Password updated, sign in with your new password". If there's no token in the URL, show a link back to /forgot-password. Add a "Forgot your password?" link on /sign-in. The reset email comes from CloudHike's sender with the wording you set on the Emails tab, and the link sends the user back to redirectTo with a token in the query.
Same rule as verification: redirectTo has to be on your Sites users can return to list. Social sign-in is a browser navigation, not a fetch: the start link can't carry the x-api-key header, and calling POST {AUTH_URL}/sign-in/social from code is refused. The provider sends the user back to the to address with the token in the URL fragment (#token=...), which browsers never send to a server, so the token stays out of logs. Here's the snippet from the docs: // Send the browser to the provider.
It returns to to with the token in the fragment. const to = location.origin + "/"; window.location.href = ${AUTH_URL}/social/github?to=${encodeURIComponent(to)}; // On your page after sign-in: take the token from the fragment, then clear it. const params = new URLSearchParams(location.hash.slice(1)); const token = params.get("token"); // send it as authorization: Bearer <token> const error = params.get("error"); // set when sign-in was not completed history.replaceState(null, "", location.pathname); We'll land on a dedicated callback page and hand the token to our server, so it ends up in the same HTTP-only cookie as email sign-in. Paste: Add "Continue with GitHub" and "Continue with Google" buttons to /sign-in and /sign-up, following the "GitHub and Google sign-in" section of the auth docs: Each button is a plain link (a page navigation) to {AUTH_URL}/social/github?to= (and /social/google for Google).
AUTH_URL is browser-safe, but build the href in server code so no new env variable is needed. Do not call POST /sign-in/social from code. /auth/callback is a client page: read token and error from location.hash, clear the fragment right away with history.replaceState, then POST the token to /api/auth/session. If error is set, show it with a link back to /sign-in.
POST /api/auth/session verifies the token by calling get-session from server code. Only when it returns a user, set the same HTTP-only "session" cookie as email sign-in and respond OK. The page then navigates to /members. Never put the token in localStorage.
Users who sign in with a provider show up in the same Users list as email users, with the email their provider gives (for GitHub, a verified primary address). Because the credential source is Shared, there's nothing else to register. Switch a provider to Your own whenever you want your own OAuth app on the consent screen. The admin endpoints need AUTH_SECRET_KEY, so they're strictly server-side.
Paste: Add an /admin page, visible only when the signed-in user's email equals an ADMIN_EMAIL env variable (add it to .env.local, and the name only to .env.example). Server code calls GET {AUTH_URL}/admin/users?search=&limit=50&offset=0 with the header x-api-key set to AUTH_SECRET_KEY and shows the users and total it returns, with a search box that fills the search parameter. AUTH_SECRET_KEY must only be read in server-only code and never reach the browser bundle. For hands-on user management, Open Auth on the Auth card lets you search and delete users.
The API also has DELETE {AUTH_URL}/admin/users/<id> with the secret key, if you ever want a delete button of your own. Your agent's MCP connection, as week 4 covered, can't delete anything. If you deployed Postgres first, Auth keeps its users in the project database's auth schema. Ask the agent to look without touching anything: Use get_project for members-club and tell me whether postgres and auth are ready.
Then use list_tables to show the schemas, and the tables in the auth schema. Don't run any query that prints emails or other personal data, and don't change anything. list_tables, describe_table and query_database are read-only on every plan (query_database runs one statement in a READ ONLY transaction), so this is safe to run any time you want to know what Auth is doing with your data. On Vercel (or any host), add AUTH_URL, AUTH_PUBLISHABLE_KEY, AUTH_SECRET_KEY and ADMIN_EMAIL (only if you built /admin) in the project settings.
In the CloudHike dashboard, Environment → Copy as .env gives you the whole file. Then: Add your production domain to Sites users can return to. Otherwise verification links, reset links and social sign-in won't send users back to it. Secure cookies.
The prompt above sets Secure in production, so the session cookie only travels over HTTPS. If the secret key leaks, click Reset keys on the Auth card. Users stay signed in, because sessions are signed with a separate per-project secret. Keep the database awake if Auth uses it.
When Auth stores users in your project database, that database must stay running, and a Free database with no connections for 6 hours is stopped until you click Wake. Pro databases are always on. If you'd rather decouple them, the Store users in project database toggle on the Auth page moves users and sessions to managed storage (sign-in s briefly during the move). Testing without touching production.
Every project can add a development environment from the switcher under the project name, with its own services, keys and .env. MCP tools take an environment argument for it. Look back at what you didn't do: you didn't install an auth library, configure SMTP, write email templates from scratch, register OAuth apps in the GitHub and Google consoles, or invent a redirect allow-list. One MCP connection and one Auth card gave you: Email and password sign-up, sign-in, sessions and sign-out as a plain HTTP API, email verification with a resend endpoint, and password reset with a token link, verification and reset emails from CloudHike's sender, with editable wording, a live preview and test sends, GitHub and Google sign-in through the shared OAuth app, with the token delivered in the URL fragment, an allow-list of return sites for every link and redirect, admin endpoints behind a server-only key, and a key reset that doesn't sign anyone out, users in your own Postgres, inspectable with read-only MCP tools.
On cost: Free holds up to 10,000 registered users per project and Pro has no limit. On both, the first 10,000 monthly active users per project are free, and additional active users cost $0.003 each per month. Everything comes out of one credit balance. If you outgrow Free, Pro is $10/month with $10 of usage credits included every month and 10 projects, and Scale is $29.99/month with unlimited projects.
The details are on the plans and billing page. Run the prompts in order: Step 3 to deploy, the Step 4 clicks, then Steps 5 to 8 for the flows. Then try to break it: sign in before verifying, open /members in a private window, sign out and press Back, request a reset for an address that has no account. 👉 Start free at cloudhike.dev.
You get $10 in credits at signup, plus $5 more with code TUBEGURUJI5, no card required. Next week: send email from your own domain. We'll verify a subdomain with DKIM, SPF and DMARC under Email → Domains, set replyTo, schedule reminders with scheduledAt, read the delivery logs, and keep it all transactional. Follow along so you don't miss it.
If you try this one, tell me in the comments which flow your agent got right first time, and which one needed a second prompt. I read every comment.
Key Takeaways #
- •Each post stands on its own, so you can start right here.
- •This story was reported by Dev.to , covering developments in thedev space.
- •AI advancements continue to reshape industries — read the full article on Dev.to for complete coverage.
📖 Continue reading the full article: