Testing and dev login
In tests
import { signInAs } from "@kaaarel/auth/testing";
import { auth } from "~/auth";
test("the deals page needs a session", async () => {
const { user, cookie, request } = await signInAs(auth, "ann@example.com");
const response = await app.fetch(request("/app/deals"));
expect(response.status).toBe(200);
});signInAscreates the user when the e-mail is new, and a session for it.request(path, init)returns aRequestwith the session cookie, and a same-originOriginheader for non-GET requests.cookieis theCookieheader value, for other HTTP clients.
Use rateLimit: false in tests that sign in many times. Use a separate schema per test file to keep tests apart. E-mails go out in the background: await auth.settled() before you read them.
Local development
devLogin: process.env.DEV_LOGIN, // e.g. "me@example.com"Open http://localhost:3000/auth/dev?next=/admin to sign in as that e-mail. It creates the user when needed. Use it when Google login cannot work locally, for example on a review proxy.
Dev login works only when all of these hold:
NODE_ENVis notproduction;- the
urlhost islocalhost,127.0.0.1,*.localhostor*.test.
In every other case /auth/dev answers 404. doctor warns while it is on.