@dbbs/strapi-stripe-payment
Version:
Strapi integration plugin for Stripe payment system
20 lines (14 loc) • 450 B
text/typescript
import createHttpError from 'http-errors'
const extractUserMiddleware = async (ctx, next) => {
try {
const user = await strapi.plugins['users-permissions'].services.jwt.getToken(ctx)
if (!user) {
throw new createHttpError.Unauthorized('User not authenticated')
}
ctx.state.user = user
} catch (err) {
throw new createHttpError.Unauthorized('Invalid token')
}
await next()
}
export default extractUserMiddleware