-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,318 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { eq } from 'drizzle-orm' | ||
import { z } from 'zod' | ||
import { users } from '~/server/db/schema' | ||
|
||
const registerRequestBody = z.object({ | ||
firebaseId: z.string().nonempty(), | ||
email: z.string().email().optional(), | ||
id: z.string().cuid2().optional(), | ||
}).refine(val => !val.email && !val.id, 'Either `email` or `id` must be provided.') | ||
|
||
export default defineProtectedEventHandler(async (event) => { | ||
const result = await registerRequestBody.safeParseAsync(await readBody(event)) | ||
if (!result.success) { | ||
throw createError({ | ||
status: 400, | ||
statusMessage: 'Bad request', | ||
}) | ||
} | ||
|
||
const { data } = result | ||
|
||
const query = data.id ? eq(users.id, data.id) : eq(users.email, data.email!) | ||
|
||
const user = await event.context.database.update(users) | ||
.set({ | ||
firebaseId: data.firebaseId, | ||
}) | ||
.where(query) | ||
.returning() | ||
|
||
return user | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX `users_id_unique` ON `users` (`id`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP INDEX IF EXISTS `users_id_unique`;--> statement-breakpoint | ||
ALTER TABLE users ADD `firebase_id` text NOT NULL;--> statement-breakpoint | ||
CREATE UNIQUE INDEX `users_firebase_id_unique` ON `users` (`firebase_id`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`); |
Oops, something went wrong.