-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
139 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
VITE_TITLE=Vite Insee Starter | ||
VITE_DESCRIPTION=Vite + TypeScript + React + react-dsfr | ||
|
||
VITE_API_URL= | ||
VITE_OIDC_ISSUER= | ||
VITE_OIDC_CLIENT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react-hooks/recommended" | ||
], | ||
'@typescript-eslint/no-unused-vars': 'warn' | ||
}, | ||
} | ||
ignorePatterns: ["dist", ".eslintrc.cjs"], | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["react-refresh"], | ||
rules: { | ||
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }], | ||
"@typescript-eslint/no-unused-vars": "warn", | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import axios, { type AxiosRequestConfig } from "axios"; | ||
import { prOidc } from "oidc"; | ||
|
||
const baseInstance = axios.create({ | ||
baseURL: import.meta.env.VITE_API_URL | ||
}); | ||
|
||
const getAccessToken = async () => { | ||
const oidc = await prOidc; | ||
|
||
if (!oidc.isUserLoggedIn) return undefined; | ||
|
||
return oidc.getTokens().accessToken; | ||
}; | ||
|
||
const onRequest = async (config: any) => ({ | ||
...config, | ||
headers: { | ||
...config.headers, | ||
"Content-Type": "application/json;charset=utf-8", | ||
Accept: "application/json;charset=utf-8", | ||
...(await (async () => { | ||
const accessToken = await getAccessToken(); | ||
|
||
if (!accessToken) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
Authorization: `Bearer ${accessToken}` | ||
}; | ||
})()) | ||
} | ||
}); | ||
|
||
baseInstance.interceptors.request.use(onRequest); | ||
|
||
// add a second `options` argument here if you want to pass extra options to each generated query | ||
export const axiosInstance = <T>(config: AxiosRequestConfig, options?: AxiosRequestConfig) => { | ||
return baseInstance<T>({ | ||
...config, | ||
...options | ||
}).then(({ data }) => data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFileRoute } from "@tanstack/react-router"; | ||
|
||
export const Route = createFileRoute("/todo/edit")({ | ||
component: () => <>Hello /todo/edit! </> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFileRoute } from "@tanstack/react-router"; | ||
|
||
export const Route = createFileRoute("/todo/")({ | ||
component: () => <>Summary</> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createFileRoute, Link, Outlet } from "@tanstack/react-router"; | ||
|
||
export const Route = createFileRoute("/todo")({ | ||
component: Layout | ||
}); | ||
|
||
function Layout() { | ||
return ( | ||
<> | ||
<h3>Todo App</h3> | ||
|
||
{( | ||
[ | ||
["/todo", "Summary"], | ||
["/todo/edit", "Edit"] | ||
] as const | ||
).map(([to, label]) => ( | ||
<Link key={to} to={to}> | ||
{label} | ||
</Link> | ||
))} | ||
<Outlet /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters