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()
|
.trim()
|
||||||
.min(8, { message: 'Password must be at least 8 characters' })
|
.min(8, { message: 'Password must be at least 8 characters' })
|
||||||
.max(128, { message: 'Password must be less than 128 characters' }),
|
.max(128, { message: 'Password must be less than 128 characters' }),
|
||||||
confirmPassword: z
|
confirm_password: z
|
||||||
.string({ required_error: 'Confirm Password is required' })
|
.string({ required_error: 'Confirm Password is required' })
|
||||||
.trim()
|
.trim()
|
||||||
.min(8, { message: 'Confirm Password must be at least 8 characters' }),
|
.min(8, { message: 'Confirm Password must be at least 8 characters' }),
|
||||||
|
|
@ -27,9 +27,9 @@ export const userSchema = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const updateUserPasswordSchema = userSchema
|
export const updateUserPasswordSchema = userSchema
|
||||||
.pick({ password: true, confirmPassword: true })
|
.pick({ password: true, confirm_password: true })
|
||||||
.superRefine(({ confirmPassword, password }, ctx) => {
|
.superRefine(({ confirm_password, password }, ctx) => {
|
||||||
if (confirmPassword !== password) {
|
if (confirm_password !== password) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: 'custom',
|
code: 'custom',
|
||||||
message: 'Password and Confirm Password must match',
|
message: 'Password and Confirm Password must match',
|
||||||
|
|
@ -38,7 +38,7 @@ export const updateUserPasswordSchema = userSchema
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: 'custom',
|
code: 'custom',
|
||||||
message: 'Password and Confirm Password must match',
|
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 { auth } from '$lib/server/lucia';
|
||||||
import prisma from '$lib/prisma.js';
|
import prisma from '$lib/prisma.js';
|
||||||
import { userSchema } from '$lib/config/zod-schemas';
|
import { userSchema } from '$lib/config/zod-schemas';
|
||||||
import { add_user_to_role } from '$db/roles';
|
|
||||||
|
|
||||||
const signInSchema = userSchema.pick({
|
const signInSchema = userSchema.pick({
|
||||||
username: true,
|
username: true,
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,30 @@ import { auth } from '$lib/server/lucia';
|
||||||
import { userSchema } from '$lib/config/zod-schemas';
|
import { userSchema } from '$lib/config/zod-schemas';
|
||||||
import { add_user_to_role } from '$db/roles';
|
import { add_user_to_role } from '$db/roles';
|
||||||
|
|
||||||
const signUpSchema = userSchema.pick({
|
const signUpSchema = userSchema
|
||||||
firstName: true,
|
.pick({
|
||||||
lastName: true,
|
firstName: true,
|
||||||
email: true,
|
lastName: true,
|
||||||
username: true,
|
email: true,
|
||||||
password: true,
|
username: true,
|
||||||
terms: 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) => {
|
export const load = async (event) => {
|
||||||
const session = await event.locals.auth.validate();
|
const session = await event.locals.auth.validate();
|
||||||
|
|
@ -50,9 +66,9 @@ export const actions = {
|
||||||
username: form.data.username,
|
username: form.data.username,
|
||||||
firstName: form.data.firstName || '',
|
firstName: form.data.firstName || '',
|
||||||
lastName: form.data.lastName || '',
|
lastName: form.data.lastName || '',
|
||||||
role: 'USER',
|
|
||||||
verified: false,
|
verified: false,
|
||||||
receiveEmail: false,
|
receiveEmail: false,
|
||||||
|
theme: 'system',
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -60,11 +76,11 @@ export const actions = {
|
||||||
|
|
||||||
console.log('User', user);
|
console.log('User', user);
|
||||||
|
|
||||||
const session = await auth.createSession(user.userId);
|
const session = await auth.createSession(user.id);
|
||||||
event.locals.auth.setSession(session);
|
event.locals.auth.setSession(session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(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 };
|
return { form };
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
lastName: true,
|
lastName: true,
|
||||||
username: true,
|
username: true,
|
||||||
email: true,
|
email: true,
|
||||||
password: true
|
password: true,
|
||||||
|
confirm_password: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const { form, errors, constraints, enhance, delayed } = superForm(data.form, {
|
const { form, errors, constraints, enhance, delayed } = superForm(data.form, {
|
||||||
|
|
@ -92,12 +93,12 @@
|
||||||
{/if}
|
{/if}
|
||||||
</label>
|
</label>
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="sr-only">password</span>
|
<span class="sr-only">Password</span>
|
||||||
<input
|
<input
|
||||||
id="password"
|
id="password"
|
||||||
name="password"
|
name="password"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="password"
|
placeholder="Password"
|
||||||
{...$constraints.username}
|
{...$constraints.username}
|
||||||
data-invalid={$errors.password}
|
data-invalid={$errors.password}
|
||||||
bind:value={$form.password}
|
bind:value={$form.password}
|
||||||
|
|
@ -108,6 +109,23 @@
|
||||||
<small>{$errors.password}</small>
|
<small>{$errors.password}</small>
|
||||||
{/if}
|
{/if}
|
||||||
</label>
|
</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>
|
<button type="submit">Signup</button>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,11 @@ export const load = async ({ fetch, url }) => {
|
||||||
skip: form.data?.skip,
|
skip: form.data?.skip,
|
||||||
client_id: BOARD_GAME_ATLAS_CLIENT_ID,
|
client_id: BOARD_GAME_ATLAS_CLIENT_ID,
|
||||||
fuzzy_match: true,
|
fuzzy_match: true,
|
||||||
name: form.data?.q,
|
name: form.data?.q
|
||||||
fields:
|
|
||||||
'id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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?.minAge) {
|
||||||
if (form.data?.exactMinAge) {
|
if (form.data?.exactMinAge) {
|
||||||
queryParams.min_age = form.data?.minAge;
|
queryParams.min_age = form.data?.minAge;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue