diff --git a/packages/codius-astro/astro.config.mjs b/packages/codius-astro/astro.config.mjs index 3a0202d..d7cf871 100644 --- a/packages/codius-astro/astro.config.mjs +++ b/packages/codius-astro/astro.config.mjs @@ -1,6 +1,7 @@ import cloudflare from "@astrojs/cloudflare" import react from "@astrojs/react" import tailwind from "@astrojs/tailwind" +import clerk from "@clerk/astro" import { defineConfig } from "astro/config" import simpleStackQuery from "simple-stack-query" @@ -17,6 +18,7 @@ export default defineConfig({ }, }), integrations: [ + clerk(), react(), tailwind({ applyBaseStyles: false, diff --git a/packages/codius-astro/package.json b/packages/codius-astro/package.json index 8d9cf4d..804f758 100644 --- a/packages/codius-astro/package.json +++ b/packages/codius-astro/package.json @@ -21,6 +21,7 @@ "@astrojs/cloudflare": "^11.0.4", "@astrojs/react": "^3.6.1", "@astrojs/tailwind": "^5.1.0", + "@clerk/astro": "^1.0.12", "@lucia-auth/adapter-sqlite": "^3.0.1", "@octokit/request-error": "^6.1.1", "@octokit/rest": "^21.0.0", diff --git a/packages/codius-astro/src/actions/index.ts b/packages/codius-astro/src/actions/index.ts index 4a1247a..de97ff7 100644 --- a/packages/codius-astro/src/actions/index.ts +++ b/packages/codius-astro/src/actions/index.ts @@ -10,14 +10,16 @@ export const server = { id: z.string(), }), handler: async ({ id }, context) => { - if (!context.locals.user) { + // TODO: protect /_actions/deleteApp in clerk? + const { userId } = context.locals.auth() + if (!userId) { throw new ActionError({ code: "UNAUTHORIZED", }) } const app = await context.locals.db.apps.delete({ id, - userId: context.locals.user.id, + userId, }) if (!app) { throw new ActionError({ @@ -60,7 +62,9 @@ export const server = { }), // https://github.com/withastro/roadmap/blob/actions/proposals/0046-actions.md#access-api-context handler: async ({ repoUrl, branch, directory }, context) => { - if (!context.locals.user) { + // TODO: protect /_actions/deployApp in clerk? + const { userId } = context.locals.auth() + if (!userId) { throw new ActionError({ code: "UNAUTHORIZED", }) @@ -73,7 +77,7 @@ export const server = { const commit = await getCommit({ owner, repo, branch }) const app = await context.locals.db.apps.create({ - userId: context.locals.user.id, + userId, githubOwner: owner, repo, branch, @@ -125,8 +129,8 @@ export const server = { const metadata: Stripe.MetadataParam = { appId, } - if (context.locals.user) { - metadata.userId = context.locals.user.id + if (context.locals.auth().userId) { + metadata.userId = context.locals.auth().userId } const session = await stripe.checkout.sessions.create({ line_items: [ diff --git a/packages/codius-astro/src/components/UserAppsTable.astro b/packages/codius-astro/src/components/UserAppsTable.astro index 6db961c..0983202 100644 --- a/packages/codius-astro/src/components/UserAppsTable.astro +++ b/packages/codius-astro/src/components/UserAppsTable.astro @@ -9,15 +9,14 @@ import { TableHeader, TableRow, } from "@/components/ui/table" -import type { User } from "lucia" interface Props { - user: User + userId: string dispatcherHostname: string } -const { dispatcherHostname, user } = Astro.props -const apps = await Astro.locals.db.apps.getByUserId(user.id) +const { dispatcherHostname, userId } = Astro.props +const apps = await Astro.locals.db.apps.getByUserId(userId) ---