- )
-}
-
-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')}
+
+
+
+ reset allowed IP
+
+ >
+ )
+}
+
+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.