Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
aiji42 committed Jul 11, 2022
1 parent 24d206f commit a36ecc9
Show file tree
Hide file tree
Showing 7 changed files with 1,066 additions and 1,119 deletions.
24 changes: 12 additions & 12 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
"lint": "next lint"
},
"dependencies": {
"@auth0/nextjs-auth0": "^1.7.0",
"@auth0/nextjs-auth0": "^1.9.1",
"@geist-ui/react": "^2.2.5",
"@geist-ui/react-icons": "^1.0.1",
"aws-amplify": "^4.3.20",
"firebase": "^9.7.0",
"firebase-admin": "^10.1.0",
"aws-amplify": "^4.3.27",
"firebase": "^9.9.0",
"firebase-admin": "^11.0.0",
"js-cookie": "^3.0.1",
"next": "12.1.5",
"next-fortress": "link:../",
"next": "12.2.2",
"next-fortress": "5.0.0-beta.1",
"nookies": "^2.5.2",
"react": "^18.1.0",
"react-dom": "18.1.0"
"react": "^18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/js-cookie": "^3.0.2",
"@types/react": "18.0.8",
"eslint": "8.14.0",
"eslint-config-next": "12.1.5",
"typescript": "4.6.4"
"@types/react": "18.0.15",
"eslint": "8.19.0",
"eslint-config-next": "12.2.2",
"typescript": "4.7.4"
}
}
51 changes: 51 additions & 0 deletions example/src/middleware.ts
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)
}
}
6 changes: 0 additions & 6 deletions example/src/pages/auth0/_middleware.ts

This file was deleted.

11 changes: 0 additions & 11 deletions example/src/pages/cognito/_middleware.ts

This file was deleted.

9 changes: 0 additions & 9 deletions example/src/pages/firebase/_middleware.ts

This file was deleted.

18 changes: 0 additions & 18 deletions example/src/pages/ip/_middleware.ts

This file was deleted.

Loading

0 comments on commit a36ecc9

Please sign in to comment.