From 9331e78e12cc60f465170764740bd0369a4486f7 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Fri, 19 Jan 2024 19:17:52 +0100 Subject: [PATCH] Fixes instanceof bug --- .../data/Generator/templates/sdk/package.json | 1 + .../Generator/templates/server/src/app.js | 2 +- .../providers/email/requestPasswordReset.ts | 2 +- .../src/auth/providers/email/resetPassword.ts | 2 +- .../server/src/auth/providers/email/signup.ts | 2 +- .../src/auth/providers/email/verifyEmail.ts | 2 +- .../templates/server/src/auth/utils.ts | 4 ++-- .../templates/server/src/auth/validation.ts | 2 +- .../templates/server/src/core/AuthError.js | 17 -------------- .../templates/server/src/core/HttpError.js | 22 ------------------- waspc/src/Wasp/Generator/ServerGenerator.hs | 2 -- 11 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 waspc/data/Generator/templates/server/src/core/AuthError.js delete mode 100644 waspc/data/Generator/templates/server/src/core/HttpError.js diff --git a/waspc/data/Generator/templates/sdk/package.json b/waspc/data/Generator/templates/sdk/package.json index b6abbdfd84..320be0c4bd 100644 --- a/waspc/data/Generator/templates/sdk/package.json +++ b/waspc/data/Generator/templates/sdk/package.json @@ -10,6 +10,7 @@ }, "exports": { "./core/HttpError": "./core/HttpError.js", + "./core/AuthError": "./core/AuthError.js", "./core/config": "./core/config.js", "./core/stitches.config": "./core/stitches.config.js", "./core/storage": "./core/storage.ts", diff --git a/waspc/data/Generator/templates/server/src/app.js b/waspc/data/Generator/templates/server/src/app.js index a15cb96cea..9db0e1b75d 100644 --- a/waspc/data/Generator/templates/server/src/app.js +++ b/waspc/data/Generator/templates/server/src/app.js @@ -1,6 +1,6 @@ import express from 'express' -import HttpError from './core/HttpError.js' +import HttpError from 'wasp/core/HttpError' import indexRouter from './routes/index.js' // TODO: Consider extracting most of this logic into createApp(routes, path) function so that diff --git a/waspc/data/Generator/templates/server/src/auth/providers/email/requestPasswordReset.ts b/waspc/data/Generator/templates/server/src/auth/providers/email/requestPasswordReset.ts index c0936bac59..194da085d5 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/email/requestPasswordReset.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/email/requestPasswordReset.ts @@ -13,7 +13,7 @@ import { import { ensureValidEmail } from "../../validation.js"; import type { EmailFromField } from '../../../email/core/types.js'; import { GetPasswordResetEmailContentFn } from './types.js'; -import HttpError from '../../../core/HttpError.js'; +import HttpError from 'wasp/core/HttpError' export function getRequestPasswordResetRoute({ fromField, diff --git a/waspc/data/Generator/templates/server/src/auth/providers/email/resetPassword.ts b/waspc/data/Generator/templates/server/src/auth/providers/email/resetPassword.ts index 3f01d47c32..6d8f0d6753 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/email/resetPassword.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/email/resetPassword.ts @@ -8,7 +8,7 @@ import { } from "../../utils.js"; import { ensureTokenIsPresent, ensurePasswordIsPresent, ensureValidPassword } from "../../validation.js"; import { tokenVerificationErrors } from "./types.js"; -import HttpError from '../../../core/HttpError.js'; +import HttpError from 'wasp/core/HttpError'; export async function resetPassword( req: Request<{ token: string; password: string; }>, diff --git a/waspc/data/Generator/templates/server/src/auth/providers/email/signup.ts b/waspc/data/Generator/templates/server/src/auth/providers/email/signup.ts index 05d5b0368a..984f38362d 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/email/signup.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/email/signup.ts @@ -18,7 +18,7 @@ import { import { ensureValidEmail, ensureValidPassword, ensurePasswordIsPresent } from "../../validation.js"; import { GetVerificationEmailContentFn } from './types.js'; import { validateAndGetUserFields } from '../../utils.js' -import HttpError from '../../../core/HttpError.js'; +import HttpError from 'wasp/core/HttpError'; import { type UserSignupFields } from '../types.js'; export function getSignupRoute({ diff --git a/waspc/data/Generator/templates/server/src/auth/providers/email/verifyEmail.ts b/waspc/data/Generator/templates/server/src/auth/providers/email/verifyEmail.ts index 7dc52d2576..de73a05ddf 100644 --- a/waspc/data/Generator/templates/server/src/auth/providers/email/verifyEmail.ts +++ b/waspc/data/Generator/templates/server/src/auth/providers/email/verifyEmail.ts @@ -7,7 +7,7 @@ import { deserializeAndSanitizeProviderData, } from '../../utils.js'; import { tokenVerificationErrors } from './types.js'; -import HttpError from '../../../core/HttpError.js'; +import HttpError from 'wasp/core/HttpError'; export async function verifyEmail( diff --git a/waspc/data/Generator/templates/server/src/auth/utils.ts b/waspc/data/Generator/templates/server/src/auth/utils.ts index 48a1f72855..bd63be6c79 100644 --- a/waspc/data/Generator/templates/server/src/auth/utils.ts +++ b/waspc/data/Generator/templates/server/src/auth/utils.ts @@ -1,8 +1,8 @@ {{={= =}=}} import { hashPassword } from './password.js' import { verify } from './jwt.js' -import AuthError from '../core/AuthError.js' -import HttpError from '../core/HttpError.js' +import AuthError from 'wasp/core/AuthError' +import HttpError from 'wasp/core/HttpError' import prisma from '../dbClient.js' import { sleep } from '../utils.js' import { diff --git a/waspc/data/Generator/templates/server/src/auth/validation.ts b/waspc/data/Generator/templates/server/src/auth/validation.ts index f384a28c87..96f755cac3 100644 --- a/waspc/data/Generator/templates/server/src/auth/validation.ts +++ b/waspc/data/Generator/templates/server/src/auth/validation.ts @@ -1,4 +1,4 @@ -import HttpError from '../core/HttpError.js'; +import HttpError from 'wasp/core/HttpError' export const PASSWORD_FIELD = 'password'; const USERNAME_FIELD = 'username'; diff --git a/waspc/data/Generator/templates/server/src/core/AuthError.js b/waspc/data/Generator/templates/server/src/core/AuthError.js deleted file mode 100644 index 2d965c168e..0000000000 --- a/waspc/data/Generator/templates/server/src/core/AuthError.js +++ /dev/null @@ -1,17 +0,0 @@ -class AuthError extends Error { - constructor (message, data, ...params) { - super(message, ...params) - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, AuthError) - } - - this.name = this.constructor.name - - if (data) { - this.data = data - } - } -} - -export default AuthError diff --git a/waspc/data/Generator/templates/server/src/core/HttpError.js b/waspc/data/Generator/templates/server/src/core/HttpError.js deleted file mode 100644 index 8a2cb04db5..0000000000 --- a/waspc/data/Generator/templates/server/src/core/HttpError.js +++ /dev/null @@ -1,22 +0,0 @@ -class HttpError extends Error { - constructor (statusCode, message, data, ...params) { - super(message, ...params) - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, HttpError) - } - - this.name = this.constructor.name - - if (!(Number.isInteger(statusCode) && statusCode >= 400 && statusCode < 600)) { - throw new Error('statusCode has to be integer in range [400, 600).') - } - this.statusCode = statusCode - - if (data) { - this.data = data - } - } -} - -export default HttpError diff --git a/waspc/src/Wasp/Generator/ServerGenerator.hs b/waspc/src/Wasp/Generator/ServerGenerator.hs index 260e70cab9..08caa5f2ea 100644 --- a/waspc/src/Wasp/Generator/ServerGenerator.hs +++ b/waspc/src/Wasp/Generator/ServerGenerator.hs @@ -221,8 +221,6 @@ genSrcDir :: AppSpec -> Generator [FileDraft] genSrcDir spec = sequence [ genFileCopy [relfile|app.js|], - genFileCopy [relfile|core/AuthError.js|], - genFileCopy [relfile|core/HttpError.js|], genDbClient spec, genConfigFile spec, genServerJs spec,