feat(medusa): Improve config loading (#1290)
This commit is contained in:
@@ -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",
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user