diff --git a/client/src/app/quotes/create.tsx b/client/src/app/quotes/create.tsx
index aafa161..15c5f64 100644
--- a/client/src/app/quotes/create.tsx
+++ b/client/src/app/quotes/create.tsx
@@ -8,7 +8,7 @@ import { t } from "i18next";
import { SubmitButton } from "@/components";
import { useWarnAboutChange } from "@/lib/hooks";
-import { Form } from "@/ui";
+import { Button, Form } from "@/ui";
import { ICreateQuote_Request_DTO } from "@shared/contexts";
import { useEffect } from "react";
import { FieldErrors, SubmitErrorHandler, SubmitHandler, useForm } from "react-hook-form";
@@ -104,12 +104,9 @@ export const QuoteCreate = () => {
/>
-
+
diff --git a/client/src/components/Layout/components/UserButton.tsx b/client/src/components/Layout/components/UserButton.tsx
index 8cb7dae..42d9a78 100644
--- a/client/src/components/Layout/components/UserButton.tsx
+++ b/client/src/components/Layout/components/UserButton.tsx
@@ -33,6 +33,7 @@ export const UserButton = () => {
},
});
const { data, status } = useGetProfile();
+ console.log(data, status);
const openUserMenu = (event: SyntheticEvent) => {
event.preventDefault();
diff --git a/client/src/components/ProtectedRoute/ProtectedRoute.tsx b/client/src/components/ProtectedRoute/ProtectedRoute.tsx
index bc4a897..8e77cfa 100644
--- a/client/src/components/ProtectedRoute/ProtectedRoute.tsx
+++ b/client/src/components/ProtectedRoute/ProtectedRoute.tsx
@@ -1,5 +1,6 @@
-import { useIsLoggedIn } from "@/lib/hooks";
-import React from "react";
+import { useGetProfile, useIsLoggedIn } from "@/lib/hooks";
+import React, { useEffect } from "react";
+import { useTranslation } from "react-i18next";
import { Navigate } from "react-router-dom";
import { LoadingOverlay } from "../LoadingOverlay";
@@ -9,8 +10,17 @@ type ProctectRouteProps = {
export const ProtectedRoute = ({ children }: ProctectRouteProps) => {
const { isPending, isSuccess, data: { authenticated, redirectTo } = {} } = useIsLoggedIn();
+ const { data: profile, ...profileStatus } = useGetProfile();
+ const { i18n } = useTranslation();
- if (isPending) {
+ useEffect(() => {
+ if (profileStatus.isSuccess && i18n.language !== profile?.lang_code) {
+ console.log(profile);
+ i18n.changeLanguage(profile?.lang_code);
+ }
+ }, [profile, profileStatus, i18n]);
+
+ if (isPending || profileStatus.isPending) {
return ;
}
diff --git a/client/src/lib/axios/createAxiosAuthActions.ts b/client/src/lib/axios/createAxiosAuthActions.ts
index 5964d55..1a37819 100644
--- a/client/src/lib/axios/createAxiosAuthActions.ts
+++ b/client/src/lib/axios/createAxiosAuthActions.ts
@@ -1,4 +1,4 @@
-import { IIdentity_Response_DTO, ILogin_DTO, ILogin_Response_DTO } from "@shared/contexts";
+import { IGetProfileResponse_DTO, ILogin_DTO, ILogin_Response_DTO } from "@shared/contexts";
import secureLocalStorage from "react-secure-storage";
import { IAuthActions } from "../hooks";
import { createAxiosInstance } from "./axiosInstance";
@@ -47,10 +47,10 @@ export const createAxiosAuthActions = (
},
check: () => {
- const profile = secureLocalStorage.getItem("uecko.auth") as ILogin_Response_DTO;
+ const authUser = secureLocalStorage.getItem("uecko.auth") as ILogin_Response_DTO;
return Promise.resolve(
- profile?.token
+ authUser?.token
? {
authenticated: true,
}
@@ -71,17 +71,17 @@ export const createAxiosAuthActions = (
*/
try {
- const result = await httpClient.request({
+ const result = await httpClient.request({
url: `${apiUrl}/profile`,
method: "GET",
});
- const { data } = result;
- const profile = secureLocalStorage.getItem("uecko.auth") as ILogin_Response_DTO;
+ const { data: profile } = result;
+ const authUser = secureLocalStorage.getItem("uecko.auth") as ILogin_Response_DTO;
- if (profile?.id === data?.id) {
- secureLocalStorage.setItem("uecko.profile", data);
- return Promise.resolve(data);
+ if (authUser?.id === profile?.id) {
+ secureLocalStorage.setItem("uecko.profile", profile);
+ return Promise.resolve(profile);
}
return Promise.resolve(null);
} catch (error) {
diff --git a/server/src/contexts/profile/infrastructure/express/controllers/getProfile/presenter/GetProfile.presenter.ts b/server/src/contexts/profile/infrastructure/express/controllers/getProfile/presenter/GetProfile.presenter.ts
index c058a05..a10c743 100644
--- a/server/src/contexts/profile/infrastructure/express/controllers/getProfile/presenter/GetProfile.presenter.ts
+++ b/server/src/contexts/profile/infrastructure/express/controllers/getProfile/presenter/GetProfile.presenter.ts
@@ -10,6 +10,7 @@ export interface IGetProfilePresenter {
export const GetProfilePresenter: IGetProfilePresenter = {
map: (profile: Profile, user: AuthUser, context: IProfileContext): IGetProfileResponse_DTO => {
return {
+ id: user.id.toString(),
name: user.name.toString(),
email: user.email.toString(),
lang_code: user.language.code,
diff --git a/shared/lib/contexts/profile/application/dto/GetProfile.dto/IGetProfile_Response.dto.ts b/shared/lib/contexts/profile/application/dto/GetProfile.dto/IGetProfile_Response.dto.ts
index 5679fbf..ce93fc6 100644
--- a/shared/lib/contexts/profile/application/dto/GetProfile.dto/IGetProfile_Response.dto.ts
+++ b/shared/lib/contexts/profile/application/dto/GetProfile.dto/IGetProfile_Response.dto.ts
@@ -1,4 +1,5 @@
export interface IGetProfileResponse_DTO {
+ id: string;
name: string;
email: string;
lang_code: string;