cleaner login and registration

This commit is contained in:
2023-07-18 12:05:30 +02:00
parent ffa4496c16
commit 70e640aa9a
12 changed files with 153 additions and 30 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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;