Compare commits
1 Commits
auth
...
94f1099083
| Author | SHA1 | Date | |
|---|---|---|---|
| 94f1099083 |
@@ -6,6 +6,7 @@ import { RegisterInput, LoginInput } from '../schemas/auth.schema.js'
|
||||
import { sendConfirmationMail } from './mail.service.js'
|
||||
import { createActionToken } from './actionToken.service.js'
|
||||
import { Errors } from '../errors/AppError.js'
|
||||
import { generateGravatarUrl } from './avatar.service.js'
|
||||
|
||||
export async function registerUser(
|
||||
prisma: PrismaClient,
|
||||
@@ -25,12 +26,13 @@ export async function registerUser(
|
||||
email: input.email,
|
||||
passwordHash,
|
||||
displayName,
|
||||
avatar: '',
|
||||
avatar: generateGravatarUrl(input.email),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
displayName: true,
|
||||
avatar:true,
|
||||
isConfirmed: true,
|
||||
createdAt: true,
|
||||
},
|
||||
@@ -63,6 +65,7 @@ export async function loginUser(prisma: PrismaClient, input: LoginInput) {
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
displayName: user.displayName,
|
||||
avatar: user.avatar,
|
||||
isConfirmed: user.isConfirmed,
|
||||
createdAt: user.createdAt,
|
||||
tokenVersion: user.tokenVersion,
|
||||
|
||||
10
src/services/avatar.service.ts
Normal file
10
src/services/avatar.service.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import crypto from 'crypto'
|
||||
|
||||
export function generateGravatarUrl(email: string, size = 200): string {
|
||||
const hash = crypto
|
||||
.createHash('md5')
|
||||
.update(email.trim().toLowerCase())
|
||||
.digest('hex')
|
||||
|
||||
return `https://www.gravatar.com/avatar/${hash}?s=${size}&d=identicon`
|
||||
}
|
||||
Reference in New Issue
Block a user