diff --git a/packages/backend/src/server/api/private/verify-email.ts b/packages/backend/src/server/api/private/verify-email.ts new file mode 100644 index 000000000..a5cc8d0a0 --- /dev/null +++ b/packages/backend/src/server/api/private/verify-email.ts @@ -0,0 +1,40 @@ +import type Koa from "koa"; +import { Users, UserProfiles } from "@/models/index.js"; +import { publishMainStream } from "@/services/stream.js"; + +export default async (ctx: Koa.Context) => { + const body = ctx.request.body; + + const code = body["code"]; + + const profile = await UserProfiles.findOneBy({ + emailVerifyCode: ctx.params.code, + }); + + if (profile != null) { + ctx.body = "Verify succeeded!"; + + await UserProfiles.update( + { userId: profile.userId }, + { + emailVerified: true, + emailVerifyCode: null, + }, + ); + + publishMainStream( + profile.userId, + "meUpdated", + await Users.pack( + profile.userId, + { id: profile.userId }, + { + detail: true, + includeSecrets: true, + }, + ), + ); + } else { + ctx.throw(404); + } +}; diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index 7d274f7d2..cd1425d6a 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -127,40 +127,6 @@ router.get("/identicon/:x", async (ctx) => { ctx.body = fs.createReadStream(temp).on("close", () => cleanup()); }); -router.get("/verify-email/:code", async (ctx) => { - const profile = await UserProfiles.findOneBy({ - emailVerifyCode: ctx.params.code, - }); - - if (profile != null) { - ctx.body = "Verify succeeded!"; - ctx.status = 200; - - await UserProfiles.update( - { userId: profile.userId }, - { - emailVerified: true, - emailVerifyCode: null, - }, - ); - - publishMainStream( - profile.userId, - "meUpdated", - await Users.pack( - profile.userId, - { id: profile.userId }, - { - detail: true, - includeSecrets: true, - }, - ), - ); - } else { - ctx.status = 404; - } -}); - mastoRouter.get("/oauth/authorize", async (ctx) => { const { client_id, state, redirect_uri } = ctx.request.query; console.log(ctx.request.req); diff --git a/packages/client/src/pages/signup-complete.vue b/packages/client/src/pages/signup-complete.vue index db06799ba..deb1f7846 100644 --- a/packages/client/src/pages/signup-complete.vue +++ b/packages/client/src/pages/signup-complete.vue @@ -35,5 +35,3 @@ definePageMetadata({ icon: "ph-user ph-bold ph-lg", }); - - diff --git a/packages/client/src/pages/verify-email.vue b/packages/client/src/pages/verify-email.vue new file mode 100644 index 000000000..43923cb1e --- /dev/null +++ b/packages/client/src/pages/verify-email.vue @@ -0,0 +1,35 @@ + + + diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts index a76c322bf..16a056de9 100644 --- a/packages/client/src/router.ts +++ b/packages/client/src/router.ts @@ -283,6 +283,10 @@ export const routes = [ path: "/signup-complete/:code", component: page(() => import("./pages/signup-complete.vue")), }, + { + path: "/verify-email/:code", + component: page(() => import("./pages/verify-email.vue")), + }, { path: "/announcements", component: page(() => import("./pages/announcements.vue")),