cleaner login and registration
This commit is contained in:
@ -11,7 +11,6 @@ import { User } from '../../../models/User';
|
||||
// recipe json in body
|
||||
export const POST: RequestHandler = async ({request}) => {
|
||||
const {username, password} = await request.json()
|
||||
// TODO: get salt from user in DB
|
||||
await dbConnect()
|
||||
let res = await User.findOne({username: username}, 'pass_hash salt').lean()
|
||||
await dbDisconnect()
|
||||
@ -31,17 +30,6 @@ export const POST: RequestHandler = async ({request}) => {
|
||||
return new Response(JSON.stringify(res))
|
||||
};
|
||||
|
||||
async function hashPassword(password) {
|
||||
try {
|
||||
const salt = await generateSalt(); // Generate a random salt
|
||||
const hashedPassword = await hash(password, salt); // Hash the password with the salt
|
||||
return { hashedPassword, salt };
|
||||
} catch (error) {
|
||||
console.error('Error hashing password:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function createJWT(username) {
|
||||
const payload = {
|
||||
username: username,
|
||||
|
@ -49,16 +49,3 @@ async function hashPassword(password, salt) {
|
||||
console.error('Error hashing password:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function createJWT(username, userSalt) {
|
||||
const payload = {
|
||||
username: username,
|
||||
};
|
||||
|
||||
const masterSecret = COOKIE_SECRET;
|
||||
const secretKey = masterSecret + userSalt;
|
||||
const jwt = sign(payload, secretKey);
|
||||
return jwt
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import { getJWTFromRequest } from '../../../utils/cookie';
|
||||
// recipe json in body
|
||||
export const GET: RequestHandler = async ({request}) => {
|
||||
const jwt = getJWTFromRequest(request)
|
||||
console.log(jwt)
|
||||
|
||||
// Set your master secret key (replace with your own secret)
|
||||
const masterSecret = COOKIE_SECRET;
|
||||
|
Reference in New Issue
Block a user