mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Adding confirm password on signup, fixing user creation, adding role on creation.
This commit is contained in:
parent
5a8726f7f0
commit
dd09cdf4c1
5 changed files with 56 additions and 23 deletions
|
|
@ -14,7 +14,7 @@ export const userSchema = z.object({
|
|||
.trim()
|
||||
.min(8, { message: 'Password must be at least 8 characters' })
|
||||
.max(128, { message: 'Password must be less than 128 characters' }),
|
||||
confirmPassword: z
|
||||
confirm_password: z
|
||||
.string({ required_error: 'Confirm Password is required' })
|
||||
.trim()
|
||||
.min(8, { message: 'Confirm Password must be at least 8 characters' }),
|
||||
|
|
@ -27,9 +27,9 @@ export const userSchema = z.object({
|
|||
});
|
||||
|
||||
export const updateUserPasswordSchema = userSchema
|
||||
.pick({ password: true, confirmPassword: true })
|
||||
.superRefine(({ confirmPassword, password }, ctx) => {
|
||||
if (confirmPassword !== password) {
|
||||
.pick({ password: true, confirm_password: true })
|
||||
.superRefine(({ confirm_password, password }, ctx) => {
|
||||
if (confirm_password !== password) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Password and Confirm Password must match',
|
||||
|
|
@ -38,7 +38,7 @@ export const updateUserPasswordSchema = userSchema
|
|||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Password and Confirm Password must match',
|
||||
path: ['confirmPassword']
|
||||
path: ['confirm_password']
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { setError, superValidate } from 'sveltekit-superforms/server';
|
|||
import { auth } from '$lib/server/lucia';
|
||||
import prisma from '$lib/prisma.js';
|
||||
import { userSchema } from '$lib/config/zod-schemas';
|
||||
import { add_user_to_role } from '$db/roles';
|
||||
|
||||
const signInSchema = userSchema.pick({
|
||||
username: true,
|
||||
|
|
|
|||
|
|
@ -4,14 +4,30 @@ import { auth } from '$lib/server/lucia';
|
|||
import { userSchema } from '$lib/config/zod-schemas';
|
||||
import { add_user_to_role } from '$db/roles';
|
||||
|
||||
const signUpSchema = userSchema.pick({
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
username: true,
|
||||
password: true,
|
||||
terms: true
|
||||
});
|
||||
const signUpSchema = userSchema
|
||||
.pick({
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
email: true,
|
||||
username: true,
|
||||
password: true,
|
||||
confirm_password: true,
|
||||
terms: true
|
||||
})
|
||||
.superRefine(({ confirm_password, password }, ctx) => {
|
||||
if (confirm_password !== password) {
|
||||
// ctx.addIssue({
|
||||
// code: 'custom',
|
||||
// message: 'Password and Confirm Password must match',
|
||||
// path: ['password']
|
||||
// });
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Password and Confirm Password must match',
|
||||
path: ['confirm_password']
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const load = async (event) => {
|
||||
const session = await event.locals.auth.validate();
|
||||
|
|
@ -50,9 +66,9 @@ export const actions = {
|
|||
username: form.data.username,
|
||||
firstName: form.data.firstName || '',
|
||||
lastName: form.data.lastName || '',
|
||||
role: 'USER',
|
||||
verified: false,
|
||||
receiveEmail: false,
|
||||
theme: 'system',
|
||||
token
|
||||
}
|
||||
});
|
||||
|
|
@ -60,11 +76,11 @@ export const actions = {
|
|||
|
||||
console.log('User', user);
|
||||
|
||||
const session = await auth.createSession(user.userId);
|
||||
const session = await auth.createSession(user.id);
|
||||
event.locals.auth.setSession(session);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return setError(form, 'email', 'Unable to create your account. Please try again.');
|
||||
return setError(form, '', 'Unable to create your account. Please try again.');
|
||||
}
|
||||
|
||||
return { form };
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
lastName: true,
|
||||
username: true,
|
||||
email: true,
|
||||
password: true
|
||||
password: true,
|
||||
confirm_password: true
|
||||
});
|
||||
|
||||
const { form, errors, constraints, enhance, delayed } = superForm(data.form, {
|
||||
|
|
@ -92,12 +93,12 @@
|
|||
{/if}
|
||||
</label>
|
||||
<label class="label">
|
||||
<span class="sr-only">password</span>
|
||||
<span class="sr-only">Password</span>
|
||||
<input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
placeholder="password"
|
||||
placeholder="Password"
|
||||
{...$constraints.username}
|
||||
data-invalid={$errors.password}
|
||||
bind:value={$form.password}
|
||||
|
|
@ -108,6 +109,23 @@
|
|||
<small>{$errors.password}</small>
|
||||
{/if}
|
||||
</label>
|
||||
<label class="label">
|
||||
<span class="sr-only">Confirm Password</span>
|
||||
<input
|
||||
id="confirm_password"
|
||||
name="confirm_password"
|
||||
type="password"
|
||||
placeholder="Confirm your password"
|
||||
{...$constraints.confirm_password}
|
||||
data-invalid={$errors.confirm_password}
|
||||
bind:value={$form.confirm_password}
|
||||
class="input"
|
||||
class:input-error={$errors.confirm_password}
|
||||
/>
|
||||
{#if $errors.confirm_password}
|
||||
<small>{$errors.confirm_password}</small>
|
||||
{/if}
|
||||
</label>
|
||||
|
||||
<button type="submit">Signup</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -67,11 +67,11 @@ export const load = async ({ fetch, url }) => {
|
|||
skip: form.data?.skip,
|
||||
client_id: BOARD_GAME_ATLAS_CLIENT_ID,
|
||||
fuzzy_match: true,
|
||||
name: form.data?.q,
|
||||
fields:
|
||||
'id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description'
|
||||
name: form.data?.q
|
||||
};
|
||||
|
||||
// fields: ('id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description');
|
||||
|
||||
if (form.data?.minAge) {
|
||||
if (form.data?.exactMinAge) {
|
||||
queryParams.min_age = form.data?.minAge;
|
||||
|
|
|
|||
Loading…
Reference in a new issue