Skip to content

Commit

Permalink
Lowercase user email
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1uev committed Oct 29, 2024
1 parent 6d82369 commit 2975db7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-check
const { Sequelize, DataTypes } = require('sequelize')

module.exports = {
async up({ context: queryInterface, appConfig }) {
await queryInterface.sequelize.query(`
UPDATE users
SET email = LOWER(email)
WHERE email <> LOWER(email)
`)
},

async down({ context: queryInterface, appConfig }) {},
}
5 changes: 3 additions & 2 deletions src/server/auth/providers/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ export const plugin: FastifyPluginCallback = async (

const sanitizeInput = (x: string) =>
x.replace(/[\u0000-\u001F\u007F-\u009F]/g, '')
const email = data.email.toLowerCase()

if (!user) {
user = await fastify.db.User.create({
fullName: sanitizeInput(data.name),
email: sanitizeInput(data.email),
email: sanitizeInput(email),
avatar: sanitizeInput(data.picture),
roles: [appConfig.getDefaultUserRoleByEmail(data.email)],
roles: [appConfig.getDefaultUserRoleByEmail(email)],
})
} else {
await user.set({ avatar: sanitizeInput(data.picture) }).save()
Expand Down

0 comments on commit 2975db7

Please sign in to comment.