updated UI, minor fixes
This commit is contained in:
parent
b5280b70a1
commit
755c56ee8a
9 changed files with 175 additions and 98 deletions
|
|
@ -16,8 +16,11 @@ import { Session } from '@generated/types';
|
|||
import { routeTree } from './routeTree.gen';
|
||||
|
||||
// Create a new router instance
|
||||
const router = createRouter({
|
||||
routeTree
|
||||
export const router = createRouter({
|
||||
routeTree,
|
||||
context: {
|
||||
isAuthenticated: false
|
||||
}
|
||||
});
|
||||
|
||||
// Register the router instance for type safety
|
||||
|
|
@ -28,13 +31,15 @@ declare module '@tanstack/react-router' {
|
|||
}
|
||||
|
||||
// Environment
|
||||
const MODE = import.meta.env.VITE_MODE || 'prod';
|
||||
const isProd = MODE === 'prod';
|
||||
const mode = import.meta.env.VITE_MODE || 'prod';
|
||||
const isProd = mode === 'prod';
|
||||
|
||||
const HOST = import.meta.env.VITE_HOST || 'localhost';
|
||||
const PORT = import.meta.env.VITE_PORT || '3000';
|
||||
export const url = `https://${HOST}:${PORT}`;
|
||||
const graphql_uri = `${url}/graphql`;
|
||||
export const appName = import.meta.env.VITE_APP_NAME || 'project-ln';
|
||||
|
||||
const host = import.meta.env.VITE_HOST || 'localhost';
|
||||
const port = import.meta.env.VITE_PORT || '3000';
|
||||
export const url = `https://${host}:${port}`;
|
||||
const graphqlUri = `${url}/graphql`;
|
||||
|
||||
function App() {
|
||||
const [authHeaders, setAuthHeaders] = useState<Session | null>(null);
|
||||
|
|
@ -60,7 +65,7 @@ function App() {
|
|||
);
|
||||
|
||||
const httpLink = new HttpLink({
|
||||
uri: graphql_uri,
|
||||
uri: graphqlUri,
|
||||
credentials: 'include',
|
||||
headers: authHeaders != null ? { authorization: JSON.stringify(authHeaders) } : undefined
|
||||
});
|
||||
|
|
@ -70,7 +75,7 @@ function App() {
|
|||
graphQLErrors.map(async error => {
|
||||
if (error.message.includes('jwt expired')) {
|
||||
const session = await refreshToken();
|
||||
if (session != undefined) setAuthHeaders(session);
|
||||
if (session !== undefined) setAuthHeaders(session);
|
||||
return forward(operation);
|
||||
}
|
||||
if (!isProd)
|
||||
|
|
@ -88,7 +93,7 @@ function App() {
|
|||
}
|
||||
|
||||
const client = new ApolloClient({
|
||||
uri: graphql_uri,
|
||||
uri: graphqlUri,
|
||||
link: from([errorLink, httpLink]),
|
||||
cache: new InMemoryCache(),
|
||||
connectToDevTools: !isProd,
|
||||
|
|
@ -100,7 +105,7 @@ function App() {
|
|||
<AuthProvider
|
||||
value={{
|
||||
headers: authHeaders,
|
||||
setHeaders: (session: Session) => {
|
||||
setHeaders: (session: Session | null) => {
|
||||
setAuthHeaders(session);
|
||||
}
|
||||
}}
|
||||
|
|
@ -108,7 +113,7 @@ function App() {
|
|||
<ApolloProvider client={client}>
|
||||
<ChakraProvider>
|
||||
<Toaster />
|
||||
<RouterProvider router={router} />
|
||||
<RouterProvider router={router} context={{ isAuthenticated: authHeaders != null }} />
|
||||
</ChakraProvider>
|
||||
</ApolloProvider>
|
||||
</AuthProvider>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue