Files
netris-nestri/infra/api.ts
Wanjohi fc5a755408 feat: Add auth flow (#146)
This adds a simple way to incorporate a centralized authentication flow.

The idea is to have the user, API and SSH (for machine authentication)
all in one place using `openauthjs` + `SST`

We also have a database now :)

> We are using InstantDB as it allows us to authenticate a use with just
the email. Plus it is super simple simple to use _of course after the
initial fumbles trying to design the db and relationships_
2025-01-04 00:02:28 +03:00

52 lines
1.1 KiB
TypeScript

import { domain } from "./dns";
import { secret } from "./secrets"
sst.Linkable.wrap(random.RandomString, (resource) => ({
properties: {
value: resource.result,
},
}));
export const authFingerprintKey = new random.RandomString(
"AuthFingerprintKey",
{
length: 32,
},
);
export const urls = new sst.Linkable("Urls", {
properties: {
api: "https://api." + domain,
auth: "https://auth." + domain,
},
});
export const kv = new sst.cloudflare.Kv("CloudflareAuthKV")
export const auth = new sst.cloudflare.Worker("Auth", {
link: [
kv,
urls,
authFingerprintKey,
secret.InstantAdminToken,
secret.InstantAppId,
secret.LoopsApiKey
],
handler: "./packages/functions/src/auth.ts",
url: true,
domain: "auth." + domain
});
export const api = new sst.cloudflare.Worker("Api", {
link: [
urls,
],
url: true,
handler: "./packages/functions/src/api/index.ts",
domain: "api." + domain
})
export const outputs = {
auth: auth.url,
api: api.url
}