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:
1 parent
05520391d1
commit
1a2f513d53
3 files changed
+12
-7
No files matched your search
@@ -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 })
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user