Skip to content

Commit ac150e6

Browse files
authored
Merge pull request #112 from ant-xuexiao/feat/support-anoymous-login
feat: support anoymous login
2 parents 72d17d3 + 6f7dea6 commit ac150e6

File tree

10 files changed

+15061
-10112
lines changed

10 files changed

+15061
-10112
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22
__pycache__/
33
*.pyc
4+
**/*.pyc
45
# dependencies
56
node_modules/
67

client/app/hooks/useFingerprint.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import useSWR from 'swr';
2+
import FingerprintJS from '@fingerprintjs/fingerprintjs'
3+
4+
export function useFingerprint() {
5+
return useSWR(['client.fingerprint'], async () => {
6+
const fpPromise = FingerprintJS.load();
7+
const fp = await fpPromise;
8+
return fp.get();
9+
}, { suspense: false })
10+
}

client/app/hooks/useUser.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
'use client';
2+
13
import {
24
getUserInfo
35
} from '@/app/services/UserController';
46
import { useQuery } from '@tanstack/react-query';
5-
6-
7+
import { useFingerprint } from './useFingerprint';
78

89
function useUser() {
9-
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;
10+
const { data } = useFingerprint();
11+
1012
return useQuery({
11-
queryKey: [`user.userinfo`],
12-
queryFn: async () => getUserInfo(),
13+
queryKey: [`user.userinfo`, data?.visitorId],
14+
queryFn: async () => getUserInfo({ clientId: data?.visitorId }),
15+
enabled: !!data?.visitorId,
1316
retry: false,
1417
});
1518
}

client/app/services/UserController.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import axios from 'axios';
22

3-
43
// Get the public bot profile by id
5-
export async function getUserInfo() {
6-
4+
export async function getUserInfo({ clientId }: { clientId?: string }) {
75
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;
8-
const response = await axios.get(`${apiDomain}/api/auth/userinfo`);
6+
const response = await axios.get(`${apiDomain}/api/auth/userinfo?clientId=${clientId}`);
97
return response.data.data;
108
}

client/components/User.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
'use client';
2+
13
import { Avatar, Button, Link } from '@nextui-org/react';
24
import useUser from '../app/hooks/useUser';
35

46
export default function Profile() {
5-
const { data: user } = useUser();
7+
const { data: user, status } = useUser();
68
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN;
79

8-
if (!user) {
10+
if (!user || status !== "success") {
911
return (
1012
<Button as={Link} color="primary" href={`${apiDomain}/api/auth/login`} variant="flat">
1113
Login

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@auth0/nextjs-auth0": "^3.3.0",
19+
"@fingerprintjs/fingerprintjs": "^4.3.0",
1920
"@next/bundle-analyzer": "^13.4.19",
2021
"@nextui-org/react": "^2.2.9",
2122
"@supabase/supabase-js": "^2.32.0",
@@ -28,7 +29,6 @@
2829
"axios": "^1.6.7",
2930
"concurrently": "^8.2.2",
3031
"dayjs": "^1.11.10",
31-
"petercat-lui": "^0.0.8",
3232
"eslint": "8.46.0",
3333
"eslint-config-next": "13.4.12",
3434
"framer-motion": "^10.16.15",
@@ -38,6 +38,7 @@
3838
"lodash": "^4.17.21",
3939
"next": "14.0.1",
4040
"openai": "^4.24.7",
41+
"petercat-lui": "^0.0.8",
4142
"postcss": "8.4.27",
4243
"react": "18.2.0",
4344
"react-dom": "18.2.0",

0 commit comments

Comments
 (0)