fix(medusa): Passport loader resolving to early (#5901)

* fix(medusa): Passport loader resolving to early

* fix(medusa): Passport loader resolving to early

* Create hungry-bikes-give.md
This commit is contained in:
Adrien de Peretti authored and GitHub committed 2023-12-18 17:02:51 +01:00
1 parent 05520391d1
commit 1a2f513d53
3 files changed
+12 -7

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Passport loader resolving to early
+1 -1
View File
@@ -184,7 +184,7 @@ export default async ({
const expActivity = Logger.activity(`Initializing express${EOL}`)
track("EXPRESS_INIT_STARTED")
await expressLoader({ app: expressApp, configModule })
await passportLoader({ app: expressApp, container, configModule })
await passportLoader({ app: expressApp, configModule })
const exAct = Logger.success(expActivity, "Express intialized") || {}
track("EXPRESS_INIT_COMPLETED", { duration: exAct.duration })
+6 -6
View File
@@ -4,27 +4,26 @@ import { Strategy as CustomStrategy } from "passport-custom"
import { ExtractJwt, Strategy as JWTStrategy } from "passport-jwt"
import { Strategy as LocalStrategy } from "passport-local"
import { AuthService } from "../services"
import { ConfigModule, MedusaContainer } from "../types/global"
import { ConfigModule } from "../types/global"
import { MedusaRequest } from "../types/routing"
export default async ({
app,
container,
configModule,
}: {
app: Express
container: MedusaContainer
configModule: ConfigModule
}): Promise<void> => {
const authService = container.resolve<AuthService>("authService")
// For good old email password authentication
passport.use(
new LocalStrategy(
{
usernameField: "email",
passwordField: "password",
passReqToCallback: true,
},
async (email, password, done) => {
async (req: MedusaRequest, email, password, done) => {
const authService = req.scope.resolve<AuthService>("authService")
try {
const { success, user } = await authService.authenticate(
email,
@@ -84,6 +83,7 @@ export default async ({
return done(null, false)
}
const authService = req.scope.resolve<AuthService>("authService")
const auth = await authService.authenticateAPIToken(token)
if (auth.success) {
done(null, auth.user)