Repository navigation
feat: add a dev-only sign-in with test personas and a local database #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
toto04
wants to merge
1
commit into
main
Choose a base branch
from
feat/dev-login
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Local development against the Docker Compose database. Copy to `.env.local`, then run | ||
| # `vp run dev:setup` once and `vp run dev`. Everything here is for your machine only. | ||
| DB_HOST=localhost | ||
| DB_PORT=55432 | ||
| DB_USER=postgres | ||
| DB_PASS=postgres | ||
| DB_NAME=polinetwork_auth | ||
|
|
||
| BETTER_AUTH_URL=http://localhost:3000 | ||
| # Public on purpose: startup refuses this value anywhere but localhost. | ||
| BETTER_AUTH_SECRET=local-development-only-secret-never-deploy-this | ||
|
|
||
| # The dev admin persona holds Master Admin through this allowlist. | ||
| IDP_ADMIN_USER_IDS=dev-admin | ||
|
|
||
| # One-click test personas on the login page and at /api/dev/login. Development builds | ||
| # only; startup refuses it unless BETTER_AUTH_URL is localhost. | ||
| DEV_LOGIN=1 | ||
|
|
||
| # Provider credentials are optional locally: copy them from `.env.example` if you need a | ||
| # real sign-in, otherwise the dev personas cover it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Local development database. `vp run dev:setup` starts it, then migrates and seeds it. | ||
| # It listens on localhost only; never point anything but local development at it. | ||
| name: polinetwork-auth | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:17-alpine | ||
| environment: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| POSTGRES_DB: polinetwork_auth | ||
| ports: | ||
| - "127.0.0.1:55432:5432" | ||
| volumes: | ||
| - db:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres -d polinetwork_auth"] | ||
| interval: 2s | ||
| timeout: 3s | ||
| retries: 15 | ||
|
|
||
| volumes: | ||
| db: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { FlaskConical, TriangleAlert } from "lucide-react"; | ||
| import { cn } from "cn"; | ||
| import { buttonVariants } from "@/components/ui/button"; | ||
| import { | ||
| DEV_LOGIN_KIND, | ||
| DEV_LOGIN_PATH, | ||
| devLoginHref, | ||
| type DevLoginListing, | ||
| type DevPersonaSummary, | ||
| } from "@/dev/shared"; | ||
|
|
||
| /** | ||
| * One-click sign-in as a test persona. Rendered only behind `import.meta.env.DEV`, and only | ||
| * once the server confirms `DEV_LOGIN=1`, so it never appears in production. | ||
| */ | ||
| export function DevLoginPanel({ redirect }: { redirect: string }) { | ||
| const [personas, setPersonas] = useState<DevPersonaSummary[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const controller = new AbortController(); | ||
| fetch(DEV_LOGIN_PATH, { signal: controller.signal }) | ||
| .then((response) => (response.ok ? (response.json() as Promise<DevLoginListing>) : null)) | ||
| .then((listing) => { | ||
| if (listing?.kind === DEV_LOGIN_KIND) setPersonas(listing.personas); | ||
| }) | ||
| .catch(() => { | ||
| /* Dev sign-in is off: show nothing. */ | ||
| }); | ||
| return () => controller.abort(); | ||
| }, []); | ||
|
|
||
| if (!personas.length) return null; | ||
| return ( | ||
| <section | ||
| aria-labelledby="dev-login-title" | ||
| className="space-y-3 rounded-xl border border-dashed border-amber-500/60 bg-amber-500/5 p-4" | ||
| > | ||
| <div> | ||
| <h2 id="dev-login-title" className="flex items-center gap-1.5 text-sm font-semibold"> | ||
| <FlaskConical className="size-4 text-amber-600 dark:text-amber-400" aria-hidden="true" /> | ||
| Dev sign-in | ||
| </h2> | ||
| <p className="mt-1 text-xs leading-5 text-muted-foreground"> | ||
| Local development only. Signs you in as a test person, no account needed. | ||
| </p> | ||
| </div> | ||
| <ul className="space-y-2"> | ||
| {personas.map((persona) => ( | ||
| <li key={persona.key}> | ||
| <a | ||
| href={devLoginHref(persona.key, redirect)} | ||
| className={cn( | ||
| buttonVariants({ variant: "outline" }), | ||
| "h-auto w-full flex-col items-start gap-0.5 bg-card px-3 py-2 text-left whitespace-normal", | ||
| )} | ||
| > | ||
| <span className="text-sm font-medium">{persona.name}</span> | ||
| <span className="text-xs font-normal text-muted-foreground"> | ||
| {persona.description} | ||
| </span> | ||
| {persona.warning && ( | ||
| <span className="flex items-start gap-1 text-xs font-normal text-amber-700 dark:text-amber-300"> | ||
| <TriangleAlert className="mt-0.5 size-3 shrink-0" aria-hidden="true" /> | ||
| {persona.warning} | ||
| </span> | ||
| )} | ||
| </a> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </section> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Resume OIDC through the authenticated continuation.
This redirect replays the original authorization query, including
prompt=loginormax_age=0. The dev endpoint creates a session outside Better Auth's normal OAuth continuation hook, which normally clears the satisfied reauthentication requirement.I reproduced both over HTTP with a registered PKCE client: an anonymous authorize request redirects to login; selecting the student persona creates a valid session; the replayed authorize request redirects back to login instead of
/consent. A request without either parameter reaches consent.Please resume through the provider's authenticated continuation and preserve validation of the signed request. Add integration coverage for
prompt=loginandmax_age=0so a successful persona sign-in reaches consent.