diff --git a/.idea/next-fortress.iml b/.idea/next-fortress.iml index 66c22de..674ed47 100644 --- a/.idea/next-fortress.iml +++ b/.idea/next-fortress.iml @@ -8,6 +8,8 @@ + + diff --git a/example/src/pages/_app.tsx b/example/src/pages/_app.tsx index b4c6a65..4ce257c 100644 --- a/example/src/pages/_app.tsx +++ b/example/src/pages/_app.tsx @@ -68,15 +68,19 @@ function MyApp({ Component, pageProps }: AppProps) { - - + + - + diff --git a/example/src/pages/auth0/authed.tsx b/example/src/pages/auth0/authed.tsx index 5cad967..723efaf 100644 --- a/example/src/pages/auth0/authed.tsx +++ b/example/src/pages/auth0/authed.tsx @@ -25,7 +25,6 @@ const Authed: VFC = () => { diff --git a/example/src/pages/auth0/index.tsx b/example/src/pages/auth0/index.tsx index 3c471e9..bb764e1 100644 --- a/example/src/pages/auth0/index.tsx +++ b/example/src/pages/auth0/index.tsx @@ -18,7 +18,7 @@ const IndexPage: VFC = () => {

This page can be accessed by anyone, with or without a login.

-

My Page can be accessed only when you are logged in.

+

You can access My Page only when you are logged in.

{!user ? ( @@ -36,7 +36,7 @@ const IndexPage: VFC = () => {

Go My Page →

-

Try it!

+ {!user &&

(Not Allowed)

}
diff --git a/example/src/pages/cognito/authed.tsx b/example/src/pages/cognito/authed.tsx index 58725e7..1dc691f 100644 --- a/example/src/pages/cognito/authed.tsx +++ b/example/src/pages/cognito/authed.tsx @@ -29,7 +29,6 @@ const Authed: VFC = () => {
diff --git a/example/src/pages/cognito/index.tsx b/example/src/pages/cognito/index.tsx index f771e00..1e25110 100644 --- a/example/src/pages/cognito/index.tsx +++ b/example/src/pages/cognito/index.tsx @@ -23,7 +23,7 @@ const IndexPage: VFC = () => {

This page can be accessed by anyone, with or without a login.

-

My Page can be accessed only when you are logged in.

+

You can access My Page only when you are logged in.

{!login ? ( @@ -44,7 +44,7 @@ const IndexPage: VFC = () => {

Go My Page →

-

Try it!

+ {!login &&

(Not Allowed)

}
diff --git a/example/src/pages/firebase/authed.tsx b/example/src/pages/firebase/authed.tsx index 877705b..4e0029a 100644 --- a/example/src/pages/firebase/authed.tsx +++ b/example/src/pages/firebase/authed.tsx @@ -21,9 +21,8 @@ const Authed: VFC = () => {

This page is accessible only to logged-in users.

-
diff --git a/example/src/pages/firebase/index.tsx b/example/src/pages/firebase/index.tsx index 2493228..e06c0b8 100644 --- a/example/src/pages/firebase/index.tsx +++ b/example/src/pages/firebase/index.tsx @@ -17,7 +17,7 @@ const IndexPage: VFC = () => {

This page can be accessed by anyone, with or without a login.

-

My Page can be accessed only when you are logged in.

+

You can access My Page only when you are logged in.

{!auth.currentUser ? ( @@ -35,7 +35,7 @@ const IndexPage: VFC = () => {

Go My Page →

-

Try it!

+ {!auth.currentUser &&

(Not Allowed)

}
diff --git a/example/src/pages/index.tsx b/example/src/pages/index.tsx index f8b28ac..9a44496 100644 --- a/example/src/pages/index.tsx +++ b/example/src/pages/index.tsx @@ -12,7 +12,7 @@ export default function Home() {
-

IP Protection →

+

IP Protect →

diff --git a/example/src/pages/ip/[bar].tsx b/example/src/pages/ip/[bar].tsx deleted file mode 100644 index ca0e1e8..0000000 --- a/example/src/pages/ip/[bar].tsx +++ /dev/null @@ -1,77 +0,0 @@ -import Head from 'next/head' -import Image from 'next/image' -import styles from '../../styles/Home.module.css' -import { GetServerSideProps } from 'next' -import { VFC } from 'react' - -export const getServerSideProps: GetServerSideProps = async (ctx) => { - return { - props: { query: ctx.query } - } -} - -const Page: VFC = (props) => { - return ( - - ) -} - -export default Page diff --git a/example/src/pages/ip/_middleware.ts b/example/src/pages/ip/_middleware.ts index 702a775..92bc9b2 100644 --- a/example/src/pages/ip/_middleware.ts +++ b/example/src/pages/ip/_middleware.ts @@ -2,7 +2,7 @@ import { makeIPInspector } from 'next-fortress' import { NextRequest, NextResponse } from 'next/server' export const middleware = (req: NextRequest) => { - if (req.nextUrl.pathname === '/ip') return + if (!req.nextUrl.pathname.includes('admin')) return const ips = req.cookies['__allowed_ips'] if (!ips) return NextResponse.redirect('/ip') diff --git a/example/src/pages/ip/admin.tsx b/example/src/pages/ip/admin.tsx new file mode 100644 index 0000000..080ec62 --- /dev/null +++ b/example/src/pages/ip/admin.tsx @@ -0,0 +1,36 @@ +import Head from 'next/head' +import { VFC } from 'react' +import { Button, Spacer, Text } from '@geist-ui/react' +import Cookies from 'js-cookie' +import { useRouter } from 'next/router' + +const Page: VFC = () => { + const router = useRouter() + const resetIPToCookie = () => { + Cookies.remove('__allowed_ips') + router.reload() + } + + return ( + <> + + Admin | IP Protect Example | Next Fortress + + + + Admin | IP protect example + + +

Your IP address is allowed to access.

+ + Allowed IPs: {Cookies.get('__allowed_ips')} + + + + + ) +} + +export default Page diff --git a/example/src/pages/ip/index.tsx b/example/src/pages/ip/index.tsx index 12eef1c..e231a0c 100644 --- a/example/src/pages/ip/index.tsx +++ b/example/src/pages/ip/index.tsx @@ -3,27 +3,33 @@ import { useEffect, VFC } from 'react' import Cookies from 'js-cookie' import { Button, Text, Spacer, Input, useInput, Link } from '@geist-ui/react' import NextLink from 'next/link' +import { useRouter } from 'next/router' const IndexPage: VFC = () => { + const router = useRouter() const { state: ips, setState: setIps, reset, bindings } = useInput('') useEffect(() => { const cookie = Cookies.get('__allowed_ips') cookie && setIps(cookie) }, []) - const setIPToCookie = () => Cookies.set('__allowed_ips', ips, { path: '/' }) + const setIPToCookie = () => { + Cookies.set('__allowed_ips', ips, { path: '/' }) + router.reload() + } const resetIPToCookie = () => { Cookies.remove('__allowed_ips') + router.reload() reset() } return ( <> - IP Control Example | Next Fortress + IP Protect Example | Next Fortress - IP control example + IP protect example

@@ -33,7 +39,7 @@ const IndexPage: VFC = () => {

First, try to go to the Admin page without entering anything (access will be denied because you do not have an allowed IP). After that, enter - the IP you want to allow (yours) and go to the admin page. + the IP you want to allow and go to the admin page again.

@@ -44,7 +50,7 @@ const IndexPage: VFC = () => { - +