Skip to content

Commit 270031d

Browse files
committed
UPDATE: replace custom hooks with lib versions
ADD: prototype of sending analytics
1 parent e7f514d commit 270031d

File tree

13 files changed

+68
-59
lines changed

13 files changed

+68
-59
lines changed

.env.example

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ KEYCLOAK_CLIENT_SECRET=
88
KEYCLOAK_REALM=
99
# generate base32 random string
1010
AUTH_SECRET=
11-
# specify the full path to the auth api (eg. http://localhost:3000/api/auth)
12-
AUTH_URL=
13-
11+
# specify the url to api backend
1412
BACKEND_URL=
15-
13+
# specify a name of web app
1614
HOSTNAME=

main-app/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ yarn-error.log*
3535
*.tsbuildinfo
3636
next-env.d.ts
3737

38-
bun.lockb
38+
bun.lockb
39+
/.env

main-app/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"tdev": "next dev --turbo",
99
"build": "next build",
1010
"start": "next start",
11-
"lint": "oxlint src & eslint src",
11+
"lint": "oxlint src & eslint src --report-unused-disable-directives",
1212
"format": "prettier src --write"
1313
},
1414
"dependencies": {
15-
"@auth/core": "^0.30.0",
15+
"@auth/core": "^0.31.0",
1616
"@heroicons/react": "^2.1.3",
1717
"@hookform/resolvers": "^3.3.4",
1818
"@preact-signals/safe-react": "^0.6.0",
@@ -35,7 +35,7 @@
3535
"framer-motion": "^11.0.28",
3636
"mini-svg-data-uri": "^1.4.4",
3737
"next": "^14.2.2",
38-
"next-auth": "5.0.0-beta.15",
38+
"next-auth": "^5.0.0-beta.18",
3939
"next-qrcode": "^2.5.1",
4040
"next-runtime-env": "^3.2.1",
4141
"next-safe-action": "^6.2.0",
@@ -50,6 +50,7 @@
5050
"sharp": "^0.33.3",
5151
"tailwind-merge": "^2.2.2",
5252
"tailwindcss-animate": "^1.0.7",
53+
"usehooks-ts": "^3.1.0",
5354
"uuid": "^9.0.1",
5455
"vaul": "^0.9.0",
5556
"zod": "^3.22.4"

main-app/src/pages-flat/main/main-page.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ export default async function MainPage({ linkUid }: { linkUid: string }) {
6969
)}
7070
>
7171
{isValidUid && (
72-
<Button size="sm" variant="outline" asChild>
72+
<Button size="sm" variant="ghost" asChild>
7373
<Link href="/main">
74-
<ArrowLeftIcon className="mr-2 size-4" />
75-
Back
74+
<ArrowLeftIcon className="size-4" />
7675
</Link>
7776
</Button>
7877
)}

main-app/src/shared/lib/use-media-query/index.ts

-3
This file was deleted.

main-app/src/shared/lib/use-media-query/use-event-listener.ts

-21
This file was deleted.

main-app/src/shared/lib/use-media-query/use-media-query.ts

-20
This file was deleted.

main-app/src/shared/ui/card.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const CardTitle = React.forwardRef<
3333
HTMLParagraphElement,
3434
React.HTMLAttributes<HTMLHeadingElement>
3535
>(({ className, ...props }, ref) => (
36-
// eslint-disable-next-line jsx-a11y/heading-has-content
3736
<h3
3837
ref={ref}
3938
className={cn(

main-app/src/widgets/description/qr-code-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { useSignal } from '@preact-signals/safe-react'
44
import FileSaver from 'file-saver'
55
import { useQRCode } from 'next-qrcode'
66
import { ReactNode, useRef } from 'react'
7+
import { useMediaQuery } from 'usehooks-ts'
78

8-
import useMediaQuery from '@/shared/lib/use-media-query'
99
import { Button } from '@/shared/ui/button'
1010
import {
1111
Dialog,

main-app/src/widgets/description/social-share-dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import {
2424
WhatsappShareButton,
2525
XIcon,
2626
} from 'react-share'
27+
import { useMediaQuery } from 'usehooks-ts'
2728

28-
import useMediaQuery from '@/shared/lib/use-media-query'
2929
import {
3030
Dialog,
3131
DialogContent,

redirect-app/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BACKEND_URL=http://172.16.2.9:2000/api/v1

redirect-app/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"tdev": "next dev --turbo -p 3001",
99
"build": "next build",
1010
"start": "next start",
11-
"lint": "oxlint src & eslint src",
11+
"lint": "oxlint src & eslint src --report-unused-disable-directives",
1212
"format": "prettier src --write"
1313
},
1414
"dependencies": {
@@ -30,13 +30,15 @@
3030
"sharp": "^0.33.3",
3131
"tailwind-merge": "^2.3.0",
3232
"tailwindcss-animate": "^1.0.7",
33+
"uuid": "^9.0.1",
3334
"zod": "^3.22.5"
3435
},
3536
"devDependencies": {
3637
"@types/node": "^20.12.7",
3738
"@types/object-hash": "^3.0.6",
3839
"@types/react": "^18.2.79",
3940
"@types/react-dom": "^18.2.25",
41+
"@types/uuid": "^9.0.8",
4042
"autoprefixer": "^10.4.19",
4143
"postcss": "^8.4.38",
4244
"tailwindcss": "^3.4.3",

redirect-app/src/middleware.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { NextURL } from 'next/dist/server/web/next-url'
2+
import { notFound } from 'next/navigation'
3+
import { NextRequest, NextResponse, userAgent } from 'next/server'
4+
import { v4 as uuidv4 } from 'uuid'
5+
6+
type UserAgent = {
7+
device: string | undefined
8+
os: string | undefined
9+
browser: string | undefined
10+
}
11+
12+
type SplittedUrl = {
13+
domain: string
14+
subdomain: string | undefined
15+
path: string
16+
}
17+
18+
const splitUrl = (url: NextURL): SplittedUrl => {
19+
const domain = url.hostname
20+
const subdomain = domain.split('.').slice(0, -2).join('.') ?? undefined
21+
const path = url.pathname
22+
return { domain, subdomain, path }
23+
}
24+
25+
const sendAnalytics = async (
26+
agent: UserAgent,
27+
userKey: string,
28+
urlParts: SplittedUrl
29+
) => {
30+
const body = JSON.stringify({ ...agent, ...urlParts, userKey })
31+
fetch(`${process.env.BACKEND_URL}/analytics`, {body, method: "POST"})
32+
}
33+
34+
export default async function middleware(request: NextRequest) {
35+
const urlParts = splitUrl(request.nextUrl)
36+
const response = NextResponse.next()
37+
const userKey = request.cookies.get('userKey')?.value ?? uuidv4()
38+
response.cookies.set('userKey', userKey)
39+
40+
const { device, os, browser, isBot } = userAgent(request)
41+
if (isBot) notFound()
42+
await sendAnalytics(
43+
{ device: device.model, os: os.name, browser: browser.name },
44+
userKey,
45+
urlParts
46+
)
47+
return response
48+
}
49+
50+
export const config = {
51+
matcher: ['/:path'],
52+
}

0 commit comments

Comments
 (0)