> {
const hashedPassword = await hash(password);
if (config.emailVerificationDisabled) {
@@ -19,16 +21,25 @@ export async function createNewUser(email: Email, password: Password): Promise<{
const verificationCode = config.emailVerificationDisabled ? undefined : generateRandomToken() as VerificationCode;
- await db.insert(usersTable).values({
- email,
- password_hash: hashedPassword,
- verification_code: verificationCode,
- verifcationCodeExpires: verificationCode ? new Date(Date.now() + 1000 * 60 * 60 * 24 * 3) : undefined
- });
-
- return {
- verificationCode
+ try {
+ await db.insert(usersTable).values({
+ email,
+ password_hash: hashedPassword,
+ verification_code: verificationCode,
+ verifcationCodeExpires: verificationCode ? new Date(Date.now() + 1000 * 60 * 60 * 24 * 3) : undefined
+ });
}
+ catch (e) {
+ log('Failed to create new user: %s', e);
+ if ((e as any).code === 'ER_DUP_ENTRY') {
+ return err('USER_EXISTS');
+ }
+ return err('UNKNOWN_ERROR');
+ }
+
+ return ok({
+ verificationCode
+ })
}
export async function loadUser(id: number) {
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 5554cd4..2428d78 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -62,7 +62,7 @@ export type SurveyParticipant = {
export type SurveySkill = {
id: SkillId;
title: string;
- description: string | undefined | null;
+ description: string | null;
}
/// Complete data for a survey including skills & participants
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
index 371ecc5..3943b4b 100644
--- a/src/routes/+error.svelte
+++ b/src/routes/+error.svelte
@@ -7,5 +7,5 @@
-
{page.error?.message}
+
{page.error?.message}
diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte
index 7ea2ec9..637a4c1 100644
--- a/src/routes/login/+page.svelte
+++ b/src/routes/login/+page.svelte
@@ -9,7 +9,7 @@