Skip to content

Commit

Permalink
fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Jan 23, 2025
1 parent 0871b23 commit dafdc69
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/studio/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import cuid2 from "@paralleldrive/cuid2"

import { normalizeEmail } from "~/utils/email"
import { db, RoleType } from "../src/server/modules/database"
import { createSite } from "./scripts/createSite"

Expand Down Expand Up @@ -33,7 +34,7 @@ async function main() {
.values({
id: cuid2.createId(),
name,
email: `${name}@open.gov.sg`,
email: normalizeEmail(`${name}@open.gov.sg`),
phone: "",
})
.onConflict((oc) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/src/server/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const isUserDeleted = async (email: string) => {
// Email is a unique field in User table
.executeTakeFirst()

return !!user?.deletedAt
return user?.deletedAt ? true : false
}
4 changes: 4 additions & 0 deletions apps/studio/src/utils/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export const isGovEmail = (value: unknown) => {
export const isValidEmail = (value: unknown) => {
return typeof value === "string" && isEmail(value)
}
/*
* Normalizes an email address to lowercase.
*/
export const normalizeEmail = (email: string): string => email.toLowerCase()
3 changes: 2 additions & 1 deletion apps/studio/tests/integration/helpers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import cuid2 from "@paralleldrive/cuid2"
import { db } from "~server/db"

import type { User } from "~server/db"
import { normalizeEmail } from "~/utils/email"
import { setUpWhitelist } from "./seed"

export const auth = async ({ id, ...user }: SetOptional<User, "id">) => {
// Ensure email is lowercase
const normalizedUser = {
...user,
email: user.email.toLowerCase(),
email: normalizeEmail(user.email),
}

await setUpWhitelist({ email: normalizedUser.email })
Expand Down

0 comments on commit dafdc69

Please sign in to comment.