-
Notifications
You must be signed in to change notification settings - Fork 0
Auth: add magic-link/session migrations and runtime datasource #44
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- Magic-link auth creates a minimal "shell" member row at link-verification time, | ||
| -- before the user has filled in the sign-up form, so full_name can no longer be required. | ||
| ALTER TABLE "members" ALTER COLUMN full_name DROP NOT NULL; | ||
|
|
||
| -- Set when the member has completed the sign-up form; NULL marks a shell account. | ||
| ALTER TABLE "members" ADD COLUMN profile_completed_at TIMESTAMPTZ; | ||
|
|
||
| -- Existing rows were created through the full sign-up form; treat them as complete. | ||
| UPDATE "members" SET profile_completed_at = created_at WHERE full_name IS NOT NULL; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| -- Single-use sign-in tokens emailed to users. Keyed by email (not member id) | ||
| -- because the member row is only created once the link is verified. | ||
| CREATE TABLE IF NOT EXISTS "magic_link_tokens" ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should figure out a style guide for SQL stuff. Should the table names be lowercase or caps or whatever standard? |
||
| id UUID PRIMARY KEY, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be uuid? Maybe investigate? |
||
| email TEXT NOT NULL, | ||
| token_hash TEXT UNIQUE NOT NULL, | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| consumed_at TIMESTAMPTZ, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
| ); | ||
|
|
||
| CREATE INDEX idx_magic_link_tokens_email ON "magic_link_tokens" (email); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| -- Spring Session JDBC schema, copied verbatim from spring-session-jdbc's | ||
| -- org/springframework/session/jdbc/schema-postgresql.sql so Flyway owns it | ||
| -- (spring.session.jdbc.initialize-schema is set to "never" in application.yml). | ||
| CREATE TABLE SPRING_SESSION ( | ||
| PRIMARY_ID CHAR(36) NOT NULL, | ||
| SESSION_ID CHAR(36) NOT NULL, | ||
| CREATION_TIME BIGINT NOT NULL, | ||
| LAST_ACCESS_TIME BIGINT NOT NULL, | ||
| MAX_INACTIVE_INTERVAL INT NOT NULL, | ||
| EXPIRY_TIME BIGINT NOT NULL, | ||
| PRINCIPAL_NAME VARCHAR(100), | ||
| CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); | ||
| CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); | ||
| CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); | ||
|
|
||
| CREATE TABLE SPRING_SESSION_ATTRIBUTES ( | ||
| SESSION_PRIMARY_ID CHAR(36) NOT NULL, | ||
| ATTRIBUTE_NAME VARCHAR(200) NOT NULL, | ||
| ATTRIBUTE_BYTES BYTEA NOT NULL, | ||
| CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), | ||
| CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) | ||
| REFERENCES SPRING_SESSION (PRIMARY_ID) ON DELETE CASCADE | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| app: | ||
| auth: | ||
| # Dev runs plain HTTP through the Vite proxy; a Secure cookie would be silently dropped. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be the case? Should we be logging in on dev too? |
||
| cookie-secure: false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| spring: | ||
| autoconfigure: | ||
| exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration | ||
| datasource: | ||
| url: jdbc:postgresql://${DATABASE_HOST:localhost}:${DATABASE_PORT:5432}/${DATABASE_NAME:patchats} | ||
| username: ${DATABASE_USER:postgres} | ||
| password: ${DATABASE_PASSWORD:} | ||
|
Comment on lines
+2
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into this and see if we should be leaning towards spring's jdbc or what not. |
||
| flyway: | ||
| # Migrations run out-of-band via the Flyway Maven plugin (`just migrate`), never at startup. | ||
| enabled: false | ||
| session: | ||
| timeout: 30d | ||
| jdbc: | ||
| # Schema is owned by Flyway (V0006) so the app never races the migration. | ||
| initialize-schema: never | ||
| mail: | ||
| host: ${SMTP_HOST:} | ||
| port: ${SMTP_PORT:587} | ||
|
|
@@ -13,9 +23,18 @@ spring: | |
| starttls: | ||
| enable: true | ||
|
|
||
| server: | ||
| # Trust X-Forwarded-* from the reverse proxy so rate limiting sees real client IPs. | ||
| forward-headers-strategy: framework | ||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotta investigate what this does. |
||
|
|
||
| app: | ||
| commit: | ||
| sha: "@commit.sha@" | ||
| email: | ||
| from: ${EMAIL_FROM:coffeechats@patinanetwork.org} | ||
| from-name: ${EMAIL_FROM_NAME:PatChats} | ||
| auth: | ||
| # Public origin of the SPA; magic links point at <base-url>/auth/verify?token=... | ||
| base-url: ${APP_BASE_URL:http://localhost:5173} | ||
| cookie-secure: ${AUTH_COOKIE_SECURE:true} | ||
| magic-link-ttl: 15m | ||
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.
Why are we sending them a magic link before they fill out the sign up form?