-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,066 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { makeAuth0Inspector } from 'next-fortress/auth0' | ||
import { NextMiddleware, NextResponse } from 'next/server' | ||
import { makeCognitoInspector } from 'next-fortress/cognito' | ||
import { makeFirebaseInspector } from 'next-fortress/firebase' | ||
import { makeIPInspector } from 'next-fortress/ip' | ||
|
||
export const middleware: NextMiddleware = async (request, event) => { | ||
if (request.nextUrl.pathname.startsWith('/auth0')) { | ||
return makeAuth0Inspector( | ||
{ type: 'redirect', destination: '/auth0' }, | ||
'/api/auth/me' | ||
)(request, event) | ||
} | ||
|
||
if (request.nextUrl.pathname.startsWith('/cognito')) { | ||
const region = process.env.NEXT_PUBLIC_COGNITO_REGION ?? '' | ||
const userPoolId = process.env.NEXT_PUBLIC_COGNITO_USER_POOL_ID ?? '' | ||
const userPoolWebClientId = | ||
process.env.NEXT_PUBLIC_COGNITO_USER_POOL_WEB_CLIENT_ID ?? '' | ||
return makeCognitoInspector( | ||
{ type: 'redirect', destination: '/cognito' }, | ||
{ region, userPoolId, userPoolWebClientId } | ||
)(request, event) | ||
} | ||
|
||
if (request.nextUrl.pathname.startsWith('/firebase')) { | ||
return makeFirebaseInspector( | ||
{ | ||
type: 'redirect', | ||
destination: '/firebase' | ||
}, | ||
(res) => res.firebase.sign_in_provider !== 'anonymous' | ||
)(request, event) | ||
} | ||
|
||
if (request.nextUrl.pathname.startsWith('/ip')) { | ||
if (!request.nextUrl.pathname.includes('admin')) return | ||
const ips = request.cookies.get('__allowed_ips') | ||
if (!ips) { | ||
if (request.method === 'OPTIONS') return new NextResponse(null) | ||
const url = request.nextUrl.clone() | ||
url.pathname = '/ip' | ||
return NextResponse.redirect(url) | ||
} | ||
|
||
return makeIPInspector(ips.split(','), { | ||
type: 'redirect', | ||
destination: '/ip' | ||
})(request, event) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.