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