From 7cd1d695526afaaf605c69ddf019587650616af5 Mon Sep 17 00:00:00 2001 From: Qin Guan Date: Sun, 17 Sep 2023 12:09:01 +0800 Subject: [PATCH] feat: add mock apis --- nuxt.config.ts | 12 ++++++------ package.json | 1 + pnpm-lock.yaml | 7 +++++++ server/api/event/[id].get.ts | 11 +++++++++++ server/api/test.get.ts | 3 --- server/api/user/[id].get.ts | 7 +++++++ server/utils/handlers.ts | 3 ++- 7 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 server/api/event/[id].get.ts delete mode 100644 server/api/test.get.ts create mode 100644 server/api/user/[id].get.ts diff --git a/nuxt.config.ts b/nuxt.config.ts index a545b5e..92f7653 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -24,12 +24,12 @@ export default defineNuxtConfig({ sessionCookie: true, }, - // appCheck: { - // debug: true, - // isTokenAutoRefreshEnabled: true, - // provider: 'ReCaptchaEnterprise', - // key: '6LfNWy8oAAAAAG9GdaqR-X8t8721YyHyILD_C6Pu', - // }, + appCheck: { + debug: process.env.FIREBASE_APP_CHECK_DEBUG_TOKEN || process.env.NODE_ENV !== 'production', + isTokenAutoRefreshEnabled: true, + provider: 'ReCaptchaEnterprise', + key: '6LfNWy8oAAAAAG9GdaqR-X8t8721YyHyILD_C6Pu', + }, }, runtimeConfig: { diff --git a/package.json b/package.json index c7a018e..92bb307 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@libsql/client": "^0.3.4", "@nuxt/devtools": "latest", "@paralleldrive/cuid2": "^2.2.2", + "dayjs": "^1.11.9", "dotenv": "^16.3.1", "drizzle-kit": "^0.19.13", "drizzle-orm": "^0.28.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da65528..a8a58be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ devDependencies: '@paralleldrive/cuid2': specifier: ^2.2.2 version: 2.2.2 + dayjs: + specifier: ^1.11.9 + version: 1.11.9 dotenv: specifier: ^16.3.1 version: 16.3.1 @@ -4114,6 +4117,10 @@ packages: engines: {node: '>= 12'} dev: true + /dayjs@1.11.9: + resolution: {integrity: sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==} + dev: true + /debug@2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} peerDependencies: diff --git a/server/api/event/[id].get.ts b/server/api/event/[id].get.ts new file mode 100644 index 0000000..f1b266e --- /dev/null +++ b/server/api/event/[id].get.ts @@ -0,0 +1,11 @@ +import dayjs from 'dayjs' + +export default defineProtectedEventHandler(event => ({ + id: event.context.params!.id, + name: 'SST Homecoming 2024', + description: 'SST Homecoming 2024', + location: 'SST', + badgeImage: 'https://www.sst.edu.sg/images/default-source/album/2019-2020/2020-01-24-homecoming/20200124_182000.jpg?sfvrsn=2', + startDateTime: dayjs(Date.now()).valueOf(), + endDateTime: dayjs(Date.now()).valueOf(), +})) diff --git a/server/api/test.get.ts b/server/api/test.get.ts deleted file mode 100644 index 73f0605..0000000 --- a/server/api/test.get.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default defineProtectedEventHandler(() => { - return 1 -}) diff --git a/server/api/user/[id].get.ts b/server/api/user/[id].get.ts new file mode 100644 index 0000000..34ac811 --- /dev/null +++ b/server/api/user/[id].get.ts @@ -0,0 +1,7 @@ +export default defineProtectedEventHandler(event => ({ + id: event.context.params!.id, + name: 'Qin Guan', + memberId: 'ABC-1', + graduationYear: 2024, + memberType: 'exco', +})) diff --git a/server/utils/handlers.ts b/server/utils/handlers.ts index ac732ed..77c7e8d 100644 --- a/server/utils/handlers.ts +++ b/server/utils/handlers.ts @@ -1,5 +1,6 @@ // @ts-expect-error Bad types import { verifyIdToken } from 'web-auth-library/google' +import type { UserToken } from 'web-auth-library/dist/google' import type { EventHandler, EventHandlerRequest } from 'h3' export function defineProtectedEventHandler( @@ -16,7 +17,7 @@ export function defineProtectedEventHandler( } const idToken = authorization.substring(7, authorization.length) - await verifyIdToken({ + const data: UserToken = await verifyIdToken({ idToken, projectId: useRuntimeConfig().firebase.projectId, })