Skip to content

Commit 63dbdbc

Browse files
committed
infra(railway): federate api login to github oauth via better-auth
1 parent eea65e2 commit 63dbdbc

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

infra/railway/auth.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Signs the JWTs.
2+
resource "random_password" "better_auth" {
3+
length = 40
4+
}

infra/railway/locals.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ locals {
1010
}
1111

1212
api_env = {
13-
PORT = tostring(var.api.port)
14-
METRICS_PORT = "9090"
15-
LOG_LEVEL = "info"
16-
OTEL_ENABLED = "false"
17-
CORS_ORIGINS = "https://$${{RAILWAY_PUBLIC_DOMAIN}}"
18-
DATABASE_URL = "$${{Postgres.DATABASE_URL}}"
13+
PORT = tostring(var.api.port)
14+
METRICS_PORT = "9090"
15+
LOG_LEVEL = "info"
16+
OTEL_ENABLED = "false"
17+
CORS_ORIGINS = "https://$${{RAILWAY_PUBLIC_DOMAIN}}"
18+
DATABASE_URL = "$${{Postgres.DATABASE_URL}}"
19+
GITHUB_CLIENT_ID = var.github.client_id
20+
GITHUB_CLIENT_SECRET = var.github.client_secret
21+
BETTER_AUTH_URL = "https://$${{RAILWAY_PUBLIC_DOMAIN}}"
22+
BETTER_AUTH_SECRET = random_password.better_auth.result
1923
}
2024

2125
# service name -> its SQL dir. Add a line to onboard another service.

infra/railway/terraform.tfvars.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ api = {
1212
port = 3002
1313
domain = null # or "api.example.com"
1414
}
15+
16+
# From the GitHub OAuth app. Callback: https://<domain>/api/auth/callback/github
17+
github = {
18+
client_id = ""
19+
client_secret = ""
20+
}

infra/railway/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ variable "api" {
1818
domain = string # null for the free *.up.railway.app URL
1919
})
2020
}
21+
22+
# The GitHub OAuth app thoth federates login to.
23+
variable "github" {
24+
type = object({
25+
client_id = string
26+
client_secret = string
27+
})
28+
sensitive = true
29+
}

0 commit comments

Comments
 (0)