Fixing issues

This commit is contained in:
2026-07-09 22:23:32 -07:00
parent f2e4730549
commit a4840c7370
12 changed files with 132 additions and 34 deletions
+5 -1
View File
@@ -1,5 +1,6 @@
import express, { Request, Response } from "express"
import { join } from "path"
import { isArray } from "lodash"
import { NODE_ENV } from "@/config"
import dbMigrationClient from "@/db/db-migration-client"
@@ -35,7 +36,10 @@ export class Migrator {
this.migrationRouter.get("/seed/:environment", async (req: Request, res: Response) => {
try {
await this.seedUp(req.params.environment)
const environment = isArray(req.params.environment)
? req.params.environment[0]
: req.params.environment
await this.seedUp(environment)
} catch (err) {
logger.error(err)
}
@@ -38,7 +38,7 @@ export async function authorizationMiddleware(
try {
const token = req.headers.authorization || ""
const user = await Users.EnsureFromAuth0TokenService.perform(token)
const user = await Users.FindFromAuth0TokenService.perform(token)
req.currentUser = user
return next()
} catch (error) {
@@ -0,0 +1,35 @@
import { auth0Integration } from "@/integrations"
import { User } from "@/models"
import { Op } from "@sequelize/core"
import BaseService from "@/services/base-service"
export class FindFromAuth0TokenService extends BaseService {
constructor(private token: string) {
super()
}
async perform(): Promise<User> {
const { auth0Subject, email } = await auth0Integration.getUserInfo(this.token)
const existingUser = await User.withScope(["asCurrentUser"]).findOne({
where: { auth0Subject },
})
if (existingUser) {
return existingUser
}
const firstTimeUser = await User.withScope(["asCurrentUser"]).findOne({
where: { [Op.or]: [{ auth0Subject: email }, { email: email }] },
})
if (firstTimeUser) {
await firstTimeUser.update({ auth0Subject })
return firstTimeUser
}
throw new Error("No user found for this token.")
}
}
export default FindFromAuth0TokenService
+1
View File
@@ -4,3 +4,4 @@ export { DestroyService } from "./destroy-service"
// Special Services
export { EnsureFromAuth0TokenService } from "./ensure-from-auth0-token-service"
export { FindFromAuth0TokenService } from "./find-from-auth0-token-service"