(request: NextRequest)
| 7 | // DO NOT remove any existing logic if you are not sure! |
| 8 | |
| 9 | export async function proxy(request: NextRequest) { |
| 10 | const response = NextResponse.next(); |
| 11 | |
| 12 | const authenticated = await runWithAmplifyServerContext({ |
| 13 | nextServerContext: { request, response }, |
| 14 | operation: async (contextSpec) => { |
| 15 | try { |
| 16 | const session = await fetchAuthSession(contextSpec); |
| 17 | return session.tokens?.accessToken !== undefined && session.tokens?.idToken !== undefined; |
| 18 | } catch (error) { |
| 19 | console.log(error); |
| 20 | return false; |
| 21 | } |
| 22 | }, |
| 23 | }); |
| 24 | |
| 25 | if (authenticated) { |
| 26 | return response; |
| 27 | } |
| 28 | |
| 29 | return NextResponse.redirect(new URL('/sign-in', request.url)); |
| 30 | } |
| 31 | |
| 32 | export const config = { |
| 33 | matcher: [ |
nothing calls this directly
no outgoing calls
no test coverage detected