feat: Update authentication middleware (#6447)

* authentication middleware update

* disable customer authentication

* call correct feature flag method

* fix authentication middleware for store/customers

* fix integration tests and add middleware for admin customers

* update seeders

* customer groups fix

* add authentication middleware for all admin endpoints

* Feat(medusa, user): require authentication for invite accept (#6448)

* initial invite token validation for authentication invocation

* remove invite auth

* remove unused import

* cleanup tests

* refactor to auth instead of auth_user

* pr feedback

* update authenticatedRequest type

* update store authenticated endpoints

* update routes with type

* fix build

* fix build

* fix build

* use auth middleware for api-keys
This commit is contained in:
Philip Korsholm
2024-02-27 13:50:18 +08:00
committed by GitHub
parent 63aea44e06
commit 7bddb58542
94 changed files with 1177 additions and 509 deletions
+12 -2
View File
@@ -4,9 +4,10 @@ import {
MedusaError,
ModulesSdkUtils,
} from "@medusajs/utils"
import jwt, { JwtPayload } from "jsonwebtoken"
import { Invite } from "@models"
import { InviteServiceTypes } from "@types"
import jwt, { JwtPayload } from "jsonwebtoken"
type InjectedDependencies = {
inviteRepository: DAL.RepositoryService
@@ -91,7 +92,16 @@ export default class InviteService<
): Promise<TEntity> {
const decoded = this.validateToken(token)
return await super.retrieve(decoded.payload.id, {}, context)
const invite = await super.retrieve(decoded.payload.id, {}, context)
if (invite.expires_at < new Date()) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"The invite has expired"
)
}
return invite
}
private generateToken(data: any): string {