mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 05:05:17 +02:00
Update visit count and password hashing
This commit is contained in:
parent
549840128f
commit
70e23b8878
3 changed files with 22 additions and 3 deletions
|
@ -20,8 +20,6 @@ export async function GET(event: RequestEvent): Promise<Response> {
|
|||
.where(eq(userVisitedAdventures.userId,event.locals.user.id))
|
||||
.execute();
|
||||
|
||||
console.log(result[0].count);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
visitCount: result[0].count,
|
||||
|
|
|
@ -3,6 +3,7 @@ import type { PageServerLoad } from "./$types";
|
|||
import { db } from "$lib/db/db.server";
|
||||
import { userTable } from "$lib/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Argon2id } from "oslo/password";
|
||||
|
||||
export const load: PageServerLoad = async (event) => {
|
||||
if (event.locals.user)
|
||||
|
@ -20,6 +21,8 @@ export const actions: Actions = {
|
|||
let firstName = formData.get("first_name");
|
||||
let lastName = formData.get("last_name");
|
||||
|
||||
let password = formData.get("password");
|
||||
|
||||
if (!userId) {
|
||||
return {
|
||||
status: 400,
|
||||
|
@ -29,6 +32,16 @@ export const actions: Actions = {
|
|||
};
|
||||
}
|
||||
|
||||
if (password) {
|
||||
let hashedPassword = await new Argon2id().hash(password);
|
||||
console.log(hashedPassword)
|
||||
await db.update(userTable)
|
||||
.set({
|
||||
hashed_password: hashedPassword
|
||||
})
|
||||
.where(eq(userTable.id, userId));
|
||||
}
|
||||
|
||||
await db.update(userTable)
|
||||
.set({
|
||||
username: username,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
id="username"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<label for="password">First Name</label>
|
||||
<label for="first_name">First Name</label>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={first_name}
|
||||
|
@ -29,6 +29,7 @@
|
|||
id="first_name"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<label for="last_name">Last Name</label>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={last_name}
|
||||
|
@ -36,6 +37,13 @@
|
|||
id="last_name"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<label for="password">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
name="password"
|
||||
id="password"
|
||||
class="block mb-2 input input-bordered w-full max-w-xs"
|
||||
/><br />
|
||||
<!-- make hidden input where the user id is -->
|
||||
<input
|
||||
type="hidden"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue