Skip to content

Commit bdbd058

Browse files
committed
Merge branch 'main' into DIAL-11-Add-DB-channeltype-channel
2 parents 9a6a2bf + 0910226 commit bdbd058

37 files changed

+1693
-112
lines changed

client/package-lock.json

Lines changed: 830 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"cmdk": "^0.2.1",
5151
"date-fns": "^3.3.1",
5252
"embla-carousel-react": "^8.0.0-rc23",
53+
"firebase": "^10.8.0",
5354
"i18next": "^23.9.0",
5455
"i18next-browser-languagedetector": "^7.2.0",
5556
"i18next-chained-backend": "^4.6.2",

client/src/apis/auth.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Auth {
1010
login(data: TLogin): Promise<TBaseResponse<TToken>> {
1111
return http_client.post(ENDPOINTS.AUTH.LOGIN, data);
1212
}
13+
1314
// TODO: SHOULD BE CHANGE TYPE ANY TO TYPE USER
1415
register(data: TRegister): Promise<TBaseResponse<any>> {
1516
return http_client.post(ENDPOINTS.AUTH.REGISTER, data);
@@ -31,6 +32,10 @@ class Auth {
3132
refreshToken(): Promise<TBaseResponse<TToken>> {
3233
return http_client.post(ENDPOINTS.AUTH.REFRESH_TOKEN);
3334
}
35+
36+
loginWithIdToken(idToken: string): Promise<TBaseResponse<TToken>> {
37+
return http_client.post(ENDPOINTS.AUTH.WITH_ID_TOKEN, { idToken });
38+
}
3439
}
3540

3641
export const auth = new Auth();

client/src/components/ui/button.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as React from 'react';
21
import { Slot } from '@radix-ui/react-slot';
32
import { cva, type VariantProps } from 'class-variance-authority';
3+
import * as React from 'react';
44

55
import { cn } from '@/lib/utils';
66
import { Loader2 } from 'lucide-react';
@@ -40,6 +40,7 @@ export interface ButtonProps
4040
VariantProps<typeof buttonVariants> {
4141
asChild?: boolean;
4242
loading?: boolean;
43+
leftIcon?: React.ReactNode;
4344
}
4445

4546
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
@@ -52,6 +53,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
5253
loading,
5354
children,
5455
disabled,
56+
leftIcon,
5557
...props
5658
},
5759
ref
@@ -64,7 +66,11 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
6466
disabled={loading || disabled}
6567
{...props}
6668
>
67-
{loading ? <Loader2 className="w-4 h-4 animate-spin mr-2" /> : null}
69+
{loading ? (
70+
<Loader2 className="w-4 h-4 animate-spin mr-2" />
71+
) : leftIcon ? (
72+
leftIcon
73+
) : null}
6874
{children}
6975
</Comp>
7076
);

client/src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const ENDPOINTS = {
88
REFRESH_TOKEN: '/auth/refresh-token',
99
FORGOT_PASSWORD: '/auth/forgot-password',
1010
RESET_PASSWORD: '/auth/reset-password',
11+
WITH_ID_TOKEN: '/auth/with-id-token',
1112
},
1213
UPLOAD: {
1314
SINGLE: '/upload/single',

client/src/hooks/auth/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export * from './use-forgot-pass';
22
export * from './use-login';
3+
export * from './use-login-with-id-token';
4+
export * from './use-login-with-provider';
35
export * from './use-register';
46
export * from './use-set-pass';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { auth } from '@/apis/auth';
2+
import { useMutation } from '@tanstack/react-query';
3+
import { useTranslation } from 'react-i18next';
4+
import { toast } from 'sonner';
5+
6+
export const useLoginWithIdToken = () => {
7+
const { t } = useTranslation('common');
8+
return useMutation({
9+
mutationFn: (idToken: string) => {
10+
return auth.loginWithIdToken(idToken);
11+
},
12+
onSuccess(data) {
13+
toast.success(data.message);
14+
},
15+
onError(err: any) {
16+
toast.error(err?.response?.data?.message || t('api_error'));
17+
},
18+
});
19+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { auth } from '@/apis/auth';
2+
import { auth as fAuth } from '@/lib/firebase';
3+
import { useMutation } from '@tanstack/react-query';
4+
import { AuthProvider, getIdToken, signInWithPopup } from 'firebase/auth';
5+
import { useTranslation } from 'react-i18next';
6+
import { toast } from 'sonner';
7+
8+
export const useLoginWithProvider = (provider: AuthProvider) => {
9+
const { t } = useTranslation('common');
10+
return useMutation({
11+
mutationFn: async () => {
12+
const user = await signInWithPopup(fAuth, provider);
13+
14+
const idToken = await getIdToken(user.user);
15+
16+
return auth.loginWithIdToken(idToken);
17+
},
18+
onSuccess(data) {
19+
toast.success(data.message);
20+
},
21+
onError(err: any) {
22+
toast.error(err?.response?.data?.message || t('api_error'));
23+
},
24+
});
25+
};

client/src/lib/firebase.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
// handle the firebase configuration
1+
import { initializeApp } from 'firebase/app';
2+
import { GoogleAuthProvider, getAuth } from 'firebase/auth';
3+
4+
const firebaseConfig = {
5+
apiKey: 'AIzaSyAUS_tTkaP0bQHBDbHImBxHf9MNXZ3-9U0',
6+
authDomain: 'dialoguebot-6674e.firebaseapp.com',
7+
projectId: 'dialoguebot-6674e',
8+
storageBucket: 'dialoguebot-6674e.appspot.com',
9+
messagingSenderId: '173106613353',
10+
appId: '1:173106613353:web:34bb3797a0588b8496e6f8',
11+
};
12+
13+
const app = initializeApp(firebaseConfig);
14+
const auth = getAuth(app);
15+
16+
const GoogleProvider = new GoogleAuthProvider();
17+
18+
export { GoogleProvider, app, auth };

client/src/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"api_error": "An error occurred while processing your request. Please try again later.",
66
"term": "By continuing, you agree to our <term>Terms of Service</term> and <privacy>Privacy Policy</privacy>.",
77
"register": "Register",
8-
"back_to_login": "Back to login"
8+
"back_to_login": "Back to login",
9+
"login_with": "Login with {{provider}}"
910
}

0 commit comments

Comments
 (0)