diff --git a/.github/workflows/ppd.yml b/.github/workflows/ppd.yml new file mode 100644 index 00000000..996389af --- /dev/null +++ b/.github/workflows/ppd.yml @@ -0,0 +1,73 @@ +name: Preprod - Build & Deploy to Scaleway + +on: + push: + branches: [preprod] + +env: + PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 + NAMESPACE_ID: a052faf9-a712-41d7-bbfa-8293ee948e70 + CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreppdw9e10llz + IMAGE_NAME: front + CONTAINER_NAME: front + +jobs: + build-and-push-image: + 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 }} + registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }} + - name: Build the Docker Image + run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + - name: Push the Docker Image to Scaleway Container Registry + run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + deploy-to-scaleway: + needs: build-and-push-image + runs-on: ubuntu-latest + environment: preprod + 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}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV + env: + SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} + - 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 }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} diff --git a/.github/workflows/prd.yml b/.github/workflows/prd.yml new file mode 100644 index 00000000..1473339a --- /dev/null +++ b/.github/workflows/prd.yml @@ -0,0 +1,73 @@ +name: Prod - Build & Deploy to Scaleway + +on: + push: + branches: [main] + +env: + PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 + NAMESPACE_ID: 17374437-5428-468c-9f41-d89787ffce0e + CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffreprdg7h5bbub + IMAGE_NAME: front + CONTAINER_NAME: front + +jobs: + build-and-push-image: + 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 }} + registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }} + - name: Build the Docker Image + run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + - name: Push the Docker Image to Scaleway Container Registry + run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + deploy-to-scaleway: + needs: build-and-push-image + runs-on: ubuntu-latest + environment: prod + 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}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV + env: + SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} + - 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 }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} diff --git a/.github/workflows/stg.yml b/.github/workflows/stg.yml new file mode 100644 index 00000000..265c12c0 --- /dev/null +++ b/.github/workflows/stg.yml @@ -0,0 +1,73 @@ +name: Staging - Build & Deploy to Scaleway + +on: + push: + branches: [staging] + +env: + PROJECT_ID: c0ed1e9e-d945-461f-920c-98c844ef1ad4 + NAMESPACE_ID: 9f949ff2-97bc-4979-ade2-1994dcaabde0 + CONTAINER_REGISTRY_ENDPOINT: rg.fr-par.scw.cloud/funcscwlecoffrestgqhhn4ixh + IMAGE_NAME: front + CONTAINER_NAME: front + +jobs: + build-and-push-image: + 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 }} + registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT }} + - name: Build the Docker Image + run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + - name: Push the Docker Image to Scaleway Container Registry + run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT }}/${{ env.IMAGE_NAME }} + deploy-to-scaleway: + needs: build-and-push-image + runs-on: ubuntu-latest + environment: staging + 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}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV + env: + SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} + - 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 }} + SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }} + SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID }} + SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }} diff --git a/devops/stg.values.yaml b/devops/stg.values.yaml index c7c97ccc..17942c29 100644 --- a/devops/stg.values.yaml +++ b/devops/stg.values.yaml @@ -18,10 +18,10 @@ lecoffreFront: limits: memory: 2Gi ingress: - host: app.stg.lecoffre.smart-chain.fr + host: app-tp.stg.lecoffre.smart-chain.fr tls: hosts: - - app.stg.lecoffre.smart-chain.fr + - app-tp.stg.lecoffre.smart-chain.fr secretName: front-tls annotations: kubernetes.io/ingress.class: nginx diff --git a/src/front/Api/BaseApiService.ts b/src/front/Api/BaseApiService.ts index 40de30f5..330551a4 100644 --- a/src/front/Api/BaseApiService.ts +++ b/src/front/Api/BaseApiService.ts @@ -1,5 +1,7 @@ import { FrontendVariables } from "@Front/Config/VariablesFront"; import CookieService from "@Front/Services/CookieService/CookieService"; +import jwt_decode from "jwt-decode"; +import JwtService, { ICustomerJwtPayload, IUserJwtPayload } from "@Front/Services/JwtService/JwtService"; export enum ContentType { JSON = "application/json", @@ -44,6 +46,7 @@ export default abstract class BaseApiService { } protected async getRequest(url: URL, token?: string, contentType?: ContentType, ref?: IRef, fileName?: string) { + await this.checkJwtToken(); const request = async () => await fetch(url, { method: "GET", @@ -53,6 +56,7 @@ export default abstract class BaseApiService { } protected async postRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { + await this.checkJwtToken(); return this.sendRequest( async () => await fetch(url, { @@ -64,6 +68,7 @@ export default abstract class BaseApiService { } protected async postRequestFormData(url: URL, body: FormData) { + await this.checkJwtToken(); return this.sendRequest( async () => await fetch(url, { @@ -75,6 +80,7 @@ export default abstract class BaseApiService { } protected async putRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { + await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PUT", @@ -86,6 +92,7 @@ export default abstract class BaseApiService { } protected async patchRequest(url: URL, body: { [key: string]: unknown } = {}) { + await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PATCH", @@ -97,6 +104,7 @@ export default abstract class BaseApiService { } protected async deleteRequest(url: URL, body: { [key: string]: unknown } = {}, token?: string) { + await this.checkJwtToken(); const request = async () => await fetch(url, { method: "DELETE", @@ -108,6 +116,7 @@ export default abstract class BaseApiService { } protected async putFormDataRequest(url: URL, body: FormData, token?: string) { + await this.checkJwtToken(); const request = async () => await fetch(url, { method: "PUT", @@ -124,6 +133,42 @@ export default abstract class BaseApiService { return this.processResponse(response, request, ref, fileName); } + private async checkJwtToken() { + const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken"); + if (!accessToken) { + return; + } + const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload; + 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"); + if (!refreshToken) { + return; + } + const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload; + if (decodedRefreshToken.exp < now) { + return; + } + await JwtService.getInstance().refreshToken(refreshToken); + } + return; + } + protected async processResponse(response: Response, request: () => Promise, ref?: IRef, fileName?: string): Promise { let responseContent: T; ref && (ref["response"] = response); diff --git a/src/front/Components/Layouts/Login/index.tsx b/src/front/Components/Layouts/Login/index.tsx index eea6e7b6..7c8ca0a1 100644 --- a/src/front/Components/Layouts/Login/index.tsx +++ b/src/front/Components/Layouts/Login/index.tsx @@ -43,7 +43,7 @@ export default function Login() { const closeContactAdminModal = useCallback(() => { setIsErrorModalOpen(0); - router.push("mailto:gtexier@notaires.fr"); + window.open("https://www.lecoffre.io/contact", "_blank"); }, [router]); useEffect(() => { @@ -120,9 +120,36 @@ export default function Login() { cancelText={"OK"}>
- L'accès à la version bêta de lecoffre.io est limité à un groupe restreint d'utilisateurs autorisés. Si vous êtes - intéressé par la participation à notre programme de bêta-test, veuillez nous contacter par email. + L'accès à la version bêta de lecoffre.io est limité à un groupe restreint d'utilisateurs autorisés. +
    +
  • + + Si vous êtes intéressé par la participation à notre programme de bêta-test, veuillez nous compléter le + formulaire :{" "} + + https://www.lecoffre.io/contact + + +
  • +
    +
  • + + Si vous avez déjà un compte bêta-testeur, veuillez vous connecter sur{" "} + + https://compte.idnot.fr/home + {" "} + et vérifier que l'adresse mail renseignée sur votre espace est identique à celle que vous nous avez + communiquée. + +
  • +