Compare commits

...

33 Commits

Author SHA1 Message Date
Sosthene
186f8f1075 Merge branch 'legacy_preprod'
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 1m33s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 5s
2025-08-03 22:08:20 +02:00
Sosthene
59920f0ef4 Merge branch 'legacy_staging' into legacy_preprod 2025-08-03 22:06:09 +02:00
Sosthene
310634c930 Merge branch 'legacy_dev' into legacy_staging 2025-08-03 22:03:05 +02:00
Sosthene
e87b1ddde5 Make authentication more reliable
All checks were successful
Test - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 1m15s
Test - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 3s
2025-08-03 21:55:36 +02:00
Sosthene
b63973a9ba update test workflow 2025-08-03 21:55:36 +02:00
omaroughriss
2d28f1a21a Update legacy_dev cicd to push on test env
All checks were successful
Test - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 11s
Test - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 5s
2025-07-29 16:05:57 +02:00
Omar Oughriss
20a333c106 Update cicd to trigger when push legacy_dev
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 13s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
2025-07-25 16:38:05 +02:00
3048e8788e Merge pull request 'legacy_preprod' (#11) from legacy_preprod into main
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 11s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 3s
Reviewed-on: #11
2025-07-17 20:09:57 +00:00
67fa4c923d Change ci event to push 2025-07-17 20:07:04 +00:00
a916a66747 Actualiser .github/workflows/demo.yml 2025-07-17 20:04:06 +00:00
a8f2d8ed75 Merge pull request 'legacy_preprod' (#10) from legacy_preprod into main
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 13s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 5s
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 14s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 3s
Reviewed-on: #10
2025-07-16 14:58:56 +00:00
omaroughriss
1621bc1d53 Merge branch 'cicd' into legacy_dev 2025-07-16 16:43:27 +02:00
omaroughriss
f55b495449 Fix schedule errors 2025-07-16 16:33:46 +02:00
omaroughriss
7ffbe26d2b Update time to UTC+1 2025-07-16 16:03:41 +02:00
omaroughriss
c34659902e Update time to UTC+2 2025-07-16 15:56:37 +02:00
omaroughriss
ea3d2d8e8d Fix cicd to use schedule event 2025-07-16 15:46:03 +02:00
affa234d65 revert 3ba6dd767d2257056fbf5f29cfa27c9311701cdd
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 14s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
revert Add conditions to use only the schedule event
2025-07-16 11:22:16 +00:00
a0ac83bf2f revert 36e1bae353cb973b2f7c63f29ea8d433f6fc54f2
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Has been skipped
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
revert Add schedule to the demo cicd
2025-07-16 11:18:25 +00:00
omaroughriss
3ba6dd767d Add conditions to use only the schedule event
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Has been skipped
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-07-16 12:55:41 +02:00
omaroughriss
36e1bae353 Add schedule to the demo cicd
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 12s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
2025-07-16 12:30:20 +02:00
omaroughriss
aa3feb4f14 Update resources dep
All checks were successful
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 2m56s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 6s
2025-07-15 15:15:42 +02:00
omaroughriss
1766dc5a75 Add demo cicd
Some checks failed
Demo - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Failing after 26s
Demo - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-07-15 15:08:27 +02:00
Sosthene
bb370900bd [bug] Don't count refused documents on progress bar for a folder 2025-07-11 13:31:51 +02:00
Sosthene
7065f07373 Fix typo on main page 2025-07-11 13:23:51 +02:00
c313f6b493 Actualiser .github/workflows/test.yml
Some checks failed
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 13s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
Test - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 17s
Test - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Failing after 4s
2025-06-20 10:21:06 +00:00
ddf6c6c79d Ajouter .github/workflows/test.yml
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 16s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 5s
2025-06-20 10:17:33 +00:00
b632729796 Actualiser package.json
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 1m58s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
Preprod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 18s
Preprod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 4s
2025-06-17 14:27:23 +00:00
ece4738b44 Actualiser .github/workflows/prd.yml
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 14s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 7s
2025-06-17 13:40:49 +00:00
21ea67e1c1 Actualiser package.json
All checks were successful
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Successful in 3m29s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Successful in 7s
2025-06-17 13:25:57 +00:00
ef4f8ac2bc Actualiser package.json
Some checks failed
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Failing after 55s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-06-17 13:24:09 +00:00
05ffd14447 Actualiser Dockerfile
Some checks failed
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Failing after 24s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-06-17 13:21:33 +00:00
ae047c9485 Actualiser package.json
Some checks failed
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Failing after 29s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-06-17 13:15:01 +00:00
b94037e4a5 Actualiser package.json
Some checks failed
Prod - Build & Deploy to Scaleway / build-and-push-image-lecoffre (push) Failing after 29s
Prod - Build & Deploy to Scaleway / deploy-to-scaleway-lecoffre (push) Has been skipped
2025-06-17 13:12:03 +00:00
11 changed files with 280 additions and 52 deletions

View File

@ -1,8 +1,8 @@
name: Prod - Build & Deploy to Scaleway name: Prod - Build & Deploy to Scaleway
on: on:
push: push:
branches: [main] branches: [main]
env: env:
@ -18,16 +18,16 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup SSH #- name: Setup SSH
run: | # run: |
mkdir -p ~/.ssh # mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa # echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa # chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts # ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
env: # env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Copy SSH #- name: Copy SSH
run: cp ~/.ssh/id_rsa id_rsa # run: cp ~/.ssh/id_rsa id_rsa
- name: Login to Scaleway Container Registry - name: Login to Scaleway Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:

74
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,74 @@
name: Test - Build & Deploy to Scaleway
on:
push:
branches: [legacy_dev]
env:
PROJECT_ID_LECOFFRE: 72d08499-37c2-412b-877e-f8af0471654a
NAMESPACE_ID_LECOFFRE: 3829c5cd-9fb0-4871-97a1-eb33e4bc1114
CONTAINER_REGISTRY_ENDPOINT_LECOFFRE: rg.fr-par.scw.cloud/funcscwlecoffretestouylprmj
IMAGE_NAME: front
CONTAINER_NAME: front
jobs:
build-and-push-image-lecoffre:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Copy SSH
run: cp ~/.ssh/id_rsa id_rsa
- name: Login to Scaleway Container Registry
uses: docker/login-action@v3
with:
username: nologin
password: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}
- name: Build the Docker Image
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
- name: Push the Docker Image to Scaleway Container Registry
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
deploy-to-scaleway-lecoffre:
needs: build-and-push-image-lecoffre
runs-on: ubuntu-latest
environment: test
steps:
- name: Install CLI
uses: scaleway/action-scw@v0
- name: Get container ID
run: |
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID_LECOFFRE}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
env:
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
- name: Deploy the container based on the new image
run: |
env_string=""
while IFS= read -r line; do
if [[ "$line" == *"="* ]]; then
key=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
if [[ -n "$key" ]]; then
env_string+="environment-variables.$key=$value "
fi
fi
done <<< "$ENV_VARS"
env_string=$(echo $env_string | sed 's/ $//')
scw container container update ${{ env.CONTAINER_ID }} $env_string
env:
ENV_VARS: ${{ secrets.ENV }}
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}

View File

@ -7,10 +7,10 @@ COPY package.json ./
RUN apk update && apk add openssh-client git RUN apk update && apk add openssh-client git
COPY id_rsa /root/.ssh/id_rsa #COPY id_rsa /root/.ssh/id_rsa
RUN chmod 600 ~/.ssh/id_rsa #RUN chmod 600 ~/.ssh/id_rsa
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa #RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts #RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
RUN npm install --frozen-lockfile RUN npm install --frozen-lockfile

View File

@ -30,7 +30,7 @@
"heroicons": "^2.1.5", "heroicons": "^2.1.5",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.167", "le-coffre-resources": "git+https://git.4nkweb.com/4nk/lecoffre-ressources.git#v2.167",
"next": "^14.2.3", "next": "^14.2.3",
"prettier": "^2.8.7", "prettier": "^2.8.7",
"react": "18.2.0", "react": "18.2.0",

View File

@ -30,6 +30,15 @@ export default abstract class BaseApiService {
} }
protected buildHeaders(contentType: ContentType) { protected buildHeaders(contentType: ContentType) {
// Don't try to access cookies during server-side rendering
if (typeof window === 'undefined') {
const headers = new Headers();
if (contentType === ContentType.JSON || contentType === ContentType.PDF) {
headers.set("Content-Type", contentType);
}
return headers;
}
const token = CookieService.getInstance().getCookie("leCoffreAccessToken"); const token = CookieService.getInstance().getCookie("leCoffreAccessToken");
const headers = new Headers(); const headers = new Headers();
@ -37,7 +46,14 @@ export default abstract class BaseApiService {
if (contentType === ContentType.JSON || contentType === ContentType.PDF) { if (contentType === ContentType.JSON || contentType === ContentType.PDF) {
headers.set("Content-Type", contentType); headers.set("Content-Type", contentType);
} }
headers.set("Authorization", `Bearer ${token}`);
// Only set Authorization header if token exists
if (token) {
headers.set("Authorization", `Bearer ${token}`);
} else {
console.warn("No access token found in cookies when building headers");
}
return headers; return headers;
} }
@ -134,38 +150,66 @@ export default abstract class BaseApiService {
} }
private async checkJwtToken() { private async checkJwtToken() {
// Don't check tokens during server-side rendering
if (typeof window === 'undefined') {
return;
}
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken"); const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
if (!accessToken) return; if (!accessToken) {
console.warn("No access token found during JWT check");
const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload; return;
const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload;
if (!userDecodedToken && !customerDecodedToken) return;
const now = Math.floor(Date.now() / 1000);
if (userDecodedToken.userId && userDecodedToken.exp < now) {
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
if (!refreshToken) {
return;
}
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
if (decodedRefreshToken.exp < now) {
return;
}
await JwtService.getInstance().refreshToken(refreshToken);
} }
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken"); try {
if (!refreshToken) { const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload;
const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload;
if (!userDecodedToken && !customerDecodedToken) {
console.warn("Invalid token format during JWT check");
return; return;
} }
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
if (decodedRefreshToken.exp < now) { const now = Math.floor(Date.now() / 1000);
return;
if (userDecodedToken.userId && userDecodedToken.exp < now) {
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
if (!refreshToken) {
console.warn("Access token expired but no refresh token found");
return;
}
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
if (decodedRefreshToken.exp < now) {
console.warn("Both access and refresh tokens are expired");
return;
}
const refreshSuccess = await JwtService.getInstance().refreshToken(refreshToken);
if (!refreshSuccess) {
console.error("Failed to refresh token");
return;
}
} }
await JwtService.getInstance().refreshToken(refreshToken);
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
if (!refreshToken) {
console.warn("Access token expired but no refresh token found");
return;
}
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
if (decodedRefreshToken.exp < now) {
console.warn("Both access and refresh tokens are expired");
return;
}
const refreshSuccess = await JwtService.getInstance().refreshToken(refreshToken);
if (!refreshSuccess) {
console.error("Failed to refresh token");
return;
}
}
} catch (error) {
console.error("Error during JWT token check:", error);
} }
return;
} }
protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> { protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> {

View File

@ -313,10 +313,11 @@ export default function DocumentTables(props: IProps) {
); );
const progress = useMemo(() => { const progress = useMemo(() => {
const total = askedDocuments.length + toValidateDocuments.length + validatedDocuments.length + refusedDocuments.length; // Exclude refused documents from total - only count documents that are still in progress
const total = askedDocuments.length + toValidateDocuments.length + validatedDocuments.length;
if (total === 0) return 0; if (total === 0) return 0;
return (validatedDocuments.length / total) * 100; return (validatedDocuments.length / total) * 100;
}, [askedDocuments.length, refusedDocuments.length, toValidateDocuments.length, validatedDocuments.length]); }, [askedDocuments.length, toValidateDocuments.length, validatedDocuments.length]);
if (documents.length === 0 && documentsNotary.length === 0) return <NoDocument />; if (documents.length === 0 && documentsNotary.length === 0) return <NoDocument />;

View File

@ -47,8 +47,10 @@ export default function FolderInformation(props: IProps) {
let validatedDocuments = 0; let validatedDocuments = 0;
folder?.customers?.forEach((customer) => { folder?.customers?.forEach((customer) => {
const documents = customer.documents; const documents = customer.documents;
total += documents?.length ?? 0; // Only count documents that are not refused (still in progress)
validatedDocuments += documents?.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0; const activeDocuments = documents?.filter((document) => document.document_status !== EDocumentStatus.REFUSED) ?? [];
total += activeDocuments.length;
validatedDocuments += activeDocuments.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length;
}); });
if (total === 0) return 0; if (total === 0) return 0;
const percentage = (validatedDocuments / total) * 100; const percentage = (validatedDocuments / total) * 100;

View File

@ -83,7 +83,7 @@ export default function StepEmail(props: IProps) {
<div className={classes["content"]}> <div className={classes["content"]}>
<div className={classes["section"]}> <div className={classes["section"]}>
<Typography typo={ETypo.TITLE_H6} color={ETypoColor.TEXT_ACCENT} className={classes["section-title"]}> <Typography typo={ETypo.TITLE_H6} color={ETypoColor.TEXT_ACCENT} className={classes["section-title"]}>
Pour les notaires et les colaborateurs : Pour les notaires et les collaborateurs :
</Typography> </Typography>
<Button onClick={redirectUserOnConnection} rightIcon={<Image alt="id-not-logo" src={idNoteLogo} />}> <Button onClick={redirectUserOnConnection} rightIcon={<Image alt="id-not-logo" src={idNoteLogo} />}>
S'identifier avec ID.not S'identifier avec ID.not

View File

@ -1,5 +1,6 @@
import Users from "@Front/Api/LeCoffreApi/Notary/Users/Users"; import Users from "@Front/Api/LeCoffreApi/Notary/Users/Users";
import JwtService from "@Front/Services/JwtService/JwtService"; import JwtService from "@Front/Services/JwtService/JwtService";
import UserStore from "@Front/Stores/UserStore";
import User from "le-coffre-resources/dist/Notary"; import User from "le-coffre-resources/dist/Notary";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
@ -7,8 +8,23 @@ export default function useUser() {
const [user, setUser] = useState<User | null>(); const [user, setUser] = useState<User | null>();
useEffect(() => { useEffect(() => {
// Don't run on server-side
if (typeof window === 'undefined') {
return;
}
// Check if user is connected before making API calls
if (!UserStore.instance.isConnected()) {
console.warn("User not connected, skipping API call");
return;
}
const decodedJwt = JwtService.getInstance().decodeJwt(); const decodedJwt = JwtService.getInstance().decodeJwt();
if (!decodedJwt) return; if (!decodedJwt) {
console.warn("No valid JWT found, skipping API call");
return;
}
Users.getInstance() Users.getInstance()
.getByUid(decodedJwt.userId, { .getByUid(decodedJwt.userId, {
q: { q: {
@ -17,6 +33,9 @@ export default function useUser() {
}) })
.then((user) => { .then((user) => {
setUser(user); setUser(user);
})
.catch((error) => {
console.error("Failed to fetch user:", error);
}); });
}, []); }, []);

View File

@ -9,10 +9,46 @@ export default class UserStore {
protected readonly event = new EventEmitter(); protected readonly event = new EventEmitter();
public accessToken: string | null = null; public accessToken: string | null = null;
public refreshToken: string | null = null; public refreshToken: string | null = null;
private initialized = false;
private constructor() {} private constructor() {
// Don't initialize tokens during server-side rendering
if (typeof window !== 'undefined') {
this.initializeFromCookies();
}
}
private initializeFromCookies() {
if (this.initialized) return;
try {
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
if (accessToken) {
this.accessToken = accessToken;
}
if (refreshToken) {
this.refreshToken = refreshToken;
}
this.initialized = true;
} catch (error) {
console.warn("Failed to initialize tokens from cookies:", error);
}
}
public isConnected(): boolean { public isConnected(): boolean {
// Ensure initialization on client side
if (typeof window !== 'undefined' && !this.initialized) {
this.initializeFromCookies();
}
// Check both instance variable and cookie to ensure consistency
if (typeof window !== 'undefined') {
const cookieToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
return !!(this.accessToken || cookieToken);
}
return !!this.accessToken; return !!this.accessToken;
} }
@ -27,6 +63,10 @@ export default class UserStore {
CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken); CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken);
CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken); CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken);
// Update instance variables
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.event.emit("connection", this.accessToken); this.event.emit("connection", this.accessToken);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -41,6 +81,10 @@ export default class UserStore {
CookieService.getInstance().deleteCookie("leCoffreAccessToken"); CookieService.getInstance().deleteCookie("leCoffreAccessToken");
CookieService.getInstance().deleteCookie("leCoffreRefreshToken"); CookieService.getInstance().deleteCookie("leCoffreRefreshToken");
// Clear instance variables
this.accessToken = null;
this.refreshToken = null;
this.event.emit("disconnection", this.accessToken); this.event.emit("disconnection", this.accessToken);
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@ -9,10 +9,46 @@ export default class UserStore {
protected readonly event = new EventEmitter(); protected readonly event = new EventEmitter();
public accessToken: string | null = null; public accessToken: string | null = null;
public refreshToken: string | null = null; public refreshToken: string | null = null;
private initialized = false;
private constructor() {} private constructor() {
// Don't initialize tokens during server-side rendering
if (typeof window !== 'undefined') {
this.initializeFromCookies();
}
}
private initializeFromCookies() {
if (this.initialized) return;
try {
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
if (accessToken) {
this.accessToken = accessToken;
}
if (refreshToken) {
this.refreshToken = refreshToken;
}
this.initialized = true;
} catch (error) {
console.warn("Failed to initialize tokens from cookies:", error);
}
}
public isConnected(): boolean { public isConnected(): boolean {
// Ensure initialization on client side
if (typeof window !== 'undefined' && !this.initialized) {
this.initializeFromCookies();
}
// Check both instance variable and cookie to ensure consistency
if (typeof window !== 'undefined') {
const cookieToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
return !!(this.accessToken || cookieToken);
}
return !!this.accessToken; return !!this.accessToken;
} }
@ -27,6 +63,10 @@ export default class UserStore {
CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken); CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken);
CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken); CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken);
// Update instance variables
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.event.emit("connection", this.accessToken); this.event.emit("connection", this.accessToken);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -41,6 +81,10 @@ export default class UserStore {
CookieService.getInstance().deleteCookie("leCoffreAccessToken"); CookieService.getInstance().deleteCookie("leCoffreAccessToken");
CookieService.getInstance().deleteCookie("leCoffreRefreshToken"); CookieService.getInstance().deleteCookie("leCoffreRefreshToken");
// Clear instance variables
this.accessToken = null;
this.refreshToken = null;
this.event.emit("disconnection", this.accessToken); this.event.emit("disconnection", this.accessToken);
} catch (error) { } catch (error) {
console.error(error); console.error(error);