feat(medusa): Improve config loading (#1290)

This commit is contained in:
Adrien de Peretti
2022-04-21 12:49:56 +02:00
committed by GitHub
parent 89a6de4660
commit 313cb0658b
25 changed files with 225 additions and 175 deletions
@@ -1,6 +1,5 @@
import _ from "lodash"
import jwt from "jsonwebtoken"
import config from "../../../../config"
import { validator } from "../../../../utils/validator"
import { IsEmail, IsNotEmpty, IsString } from "class-validator"
import AuthService from "../../../../services/auth"
@@ -28,10 +27,11 @@ import { MedusaError } from "medusa-core-utils"
* $ref: "#/components/schemas/user"
*/
export default async (req, res) => {
if (!config.jwtSecret) {
const { projectConfig: { jwt_secret } } = req.scope.resolve('configModule')
if (!jwt_secret) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
"Please configure jwtSecret in your environment"
"Please configure jwt_secret in your environment"
)
}
const validated = await validator(AdminPostAuthReq, req.body)
@@ -44,7 +44,7 @@ export default async (req, res) => {
if (result.success && result.user) {
// Add JWT to cookie
req.session.jwt = jwt.sign({ userId: result.user.id }, config.jwtSecret, {
req.session.jwt = jwt.sign({ userId: result.user.id }, jwt_secret, {
expiresIn: "24h",
})