Skip to content

Commit

Permalink
making email check case insensitive and fixing db schema mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
aerotow committed Sep 3, 2024
1 parent 8938dd3 commit 886e949
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/server/api/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export const userRouter = createTRPCRouter({
try {
const authResult = await authenticateUser(input.email, input.password);

const approvedEmails = process.env.APPROVED_EMAILS!.split(",");
const approvedEmails = process.env.APPROVED_EMAILS!.split(",").map(email => email.toLowerCase());

if (!approvedEmails.includes(input.email)) {
if (!approvedEmails.includes(input.email.toLowerCase())) {
throw new AuthError("Email not approved");
}

Expand Down
18 changes: 13 additions & 5 deletions src/server/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
varchar,
} from "drizzle-orm/pg-core";


export const createTable = pgTableCreator((name) => `8slp_${name}`); // also in drizzle.config.ts


export const users = createTable("users", {
email: varchar("email", { length: 255 }).notNull().primaryKey(),
eightUserId: varchar("eightUserId", { length: 255 }).notNull(),
Expand All @@ -23,7 +21,7 @@ export const users = createTable("users", {
});

export const userTemperatureProfile = createTable("userTemperatureProfiles", {
email: varchar('user_id').references(() => users.email).primaryKey(),
email: varchar('email', { length: 255 }).references(() => users.email).primaryKey(),
bedTime: time("bedTime").notNull(),
wakeupTime: time("wakeupTime").notNull(),
initialSleepLevel: integer("initialSleepLevel").notNull(),
Expand All @@ -35,5 +33,15 @@ export const userTemperatureProfile = createTable("userTemperatureProfiles", {
});

export const usersRelations = relations(users, ({ one }) => ({
userTemperatureProfile: one(userTemperatureProfile),
}));
temperatureProfile: one(userTemperatureProfile, {
fields: [users.email],
references: [userTemperatureProfile.email],
}),
}));

export const userTemperatureProfileRelations = relations(userTemperatureProfile, ({ one }) => ({
user: one(users, {
fields: [userTemperatureProfile.email],
references: [users.email],
}),
}));

0 comments on commit 886e949

Please sign in to comment.