(req: RequestWithUser)
| 29 | }; |
| 30 | |
| 31 | export const withMobileAuth = async (req: RequestWithUser) => { |
| 32 | if (req.headers.get('Auth-Key')) { |
| 33 | return NextResponse.next(); |
| 34 | } |
| 35 | const token = req.headers.get('Authorization'); |
| 36 | |
| 37 | if (!token) { |
| 38 | return NextResponse.json({ message: 'Unauthorized' }, { status: 403 }); |
| 39 | } |
| 40 | const payload = await verifyJWT(token); |
| 41 | if (!payload) { |
| 42 | return NextResponse.json({ message: 'Unauthorized' }, { status: 403 }); |
| 43 | } |
| 44 | const newHeaders = new Headers(req.headers); |
| 45 | |
| 46 | /** |
| 47 | * Add a global object 'g' |
| 48 | * it holds the request claims and other keys |
| 49 | * easily pass around this key as request context |
| 50 | */ |
| 51 | newHeaders.set('g', JSON.stringify(payload)); |
| 52 | return NextResponse.next({ |
| 53 | request: { |
| 54 | headers: newHeaders, |
| 55 | }, |
| 56 | }); |
| 57 | }; |
| 58 | |
| 59 | const withAuth = async (req: NextRequestWithAuth) => { |
| 60 | if (process.env.LOCAL_CMS_PROVIDER) return; |
no test coverage detected