refactor: extract password hashing functions into a dedicated password module
This commit is contained in:
+2
-1
@@ -3,7 +3,8 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
|
||||
import { hashPassword, verifyPassword, encrypt, decrypt } from '@/lib/auth'
|
||||
import { encrypt, decrypt } from '@/lib/auth'
|
||||
import { hashPassword, verifyPassword } from '@/lib/password'
|
||||
import { cookies } from 'next/headers'
|
||||
import { sendMattermostNotification } from '@/lib/mattermost'
|
||||
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
import { SignJWT, jwtVerify } from 'jose'
|
||||
import bcrypt from 'bcryptjs'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
const secretKey = process.env.JWT_SECRET
|
||||
const key = new TextEncoder().encode(secretKey)
|
||||
|
||||
export async function hashPassword(password: string) {
|
||||
return await bcrypt.hash(password, 10)
|
||||
}
|
||||
|
||||
export async function verifyPassword(password: string, hash: string) {
|
||||
return await bcrypt.compare(password, hash)
|
||||
}
|
||||
|
||||
export async function encrypt(payload: any) {
|
||||
return await new SignJWT(payload).setProtectedHeader({ alg: 'HS256' }).setIssuedAt().sign(key) // No expiration as requested
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
export async function hashPassword(password: string) {
|
||||
return await bcrypt.hash(password, 10)
|
||||
}
|
||||
|
||||
export async function verifyPassword(password: string, hash: string) {
|
||||
return await bcrypt.compare(password, hash)
|
||||
}
|
||||
Reference in New Issue
Block a user