feat(auth): Make token auth default (#6305)

**What**
- make token auth the default being returned from authentication endpoints in api-v2
- Add `auth/session` to convert token to session based auth
- add regex-scopes to authenticate middleware 

Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
This commit is contained in:
Philip Korsholm
2024-02-05 08:17:08 +00:00
committed by GitHub
co-authored by Sebastian Rindom
parent 96ba49329b
commit e2738ab91d
21 changed files with 147 additions and 138 deletions
@@ -1,8 +1,11 @@
import { ICustomerModuleService, IAuthModuleService } from "@medusajs/types"
import { IAuthModuleService, ICustomerModuleService } from "@medusajs/types"
import jwt from "jsonwebtoken"
export const createAuthenticatedCustomer = async (
customerModuleService: ICustomerModuleService,
authService: IAuthModuleService
authService: IAuthModuleService,
jwtSecret: string
) => {
const customer = await customerModuleService.create({
first_name: "John",
@@ -12,12 +15,12 @@ export const createAuthenticatedCustomer = async (
const authUser = await authService.createAuthUser({
entity_id: "store_user",
provider_id: "test",
provider: "emailpass",
scope: "store",
app_metadata: { customer_id: customer.id },
})
const jwt = await authService.generateJwtToken(authUser.id, "store")
const token = jwt.sign(authUser, jwtSecret)
return { customer, authUser, jwt }
return { customer, authUser, jwt: token }
}