Skip to content

Commit 6ce48ec

Browse files
committed
fix admin login
1 parent 0038c79 commit 6ce48ec

File tree

6 files changed

+64
-14
lines changed

6 files changed

+64
-14
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
VITE_PORT=3000
2-
VITE_ENV_API_URL=127.0.0.1
2+
VITE_ENV_API_URL=localhost
33
EXPOSED_PORT=3002

models/ccn-coverage-models

src/admin/Login.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const theme = createTheme();
1616

1717
export default function Login() {
1818
const [open, setOpen] = React.useState(false);
19+
const [errorMessage, setErrorMessage] = React.useState("");
1920
const handleClose = (
2021
event?: React.SyntheticEvent | Event,
2122
reason?: string,
@@ -52,12 +53,14 @@ export default function Login() {
5253
.then(res => {
5354
const { data, error } = res;
5455
if (!data || error) {
55-
console.log(`Unable to login: ${error}`);
56+
console.log(`Unable to login: ${error.error}`);
57+
setErrorMessage(error.error);
5658
setOpen(true);
5759
return;
5860
}
5961

60-
if (data === 'success') {
62+
if (data.result === 'success') {
63+
console.log('Login successful');
6164
window.open('/admin/users', '_self');
6265
} else {
6366
setOpen(true);
@@ -133,7 +136,7 @@ export default function Login() {
133136
severity='error'
134137
sx={{ width: '100%' }}
135138
>
136-
Incorrect username or password
139+
Incorrect username or password: {errorMessage}
137140
</Alert>
138141
</Snackbar>
139142
</Box>

src/types/api.d.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -847,24 +847,34 @@ export interface paths {
847847
[name: string]: unknown;
848848
};
849849
content: {
850-
'text/plain': string;
850+
'application/json': {
851+
/** @example success */
852+
result: string;
853+
};
851854
};
852855
};
853-
/** @description Redirect to success or failure page */
854-
302: {
856+
/** @description Authentication failed */
857+
401: {
855858
headers: {
856-
Location?: string;
857859
[name: string]: unknown;
858860
};
859-
content?: never;
861+
content: {
862+
'application/json': {
863+
/** @example Invalid credentials */
864+
error: string;
865+
};
866+
};
860867
};
861-
/** @description Authentication failed */
862-
401: {
868+
/** @description Server error */
869+
500: {
863870
headers: {
864871
[name: string]: unknown;
865872
};
866873
content: {
867-
'text/plain': string;
874+
'application/json': {
875+
/** @example Failed to establish session */
876+
error: string;
877+
};
868878
};
869879
};
870880
};

src/utils/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import createClient from 'openapi-fetch';
22
import type { paths } from '../types/api';
33
import { API_URL } from './config';
44

5-
export const apiClient = createClient<paths>({ baseUrl: API_URL });
5+
export const apiClient = createClient<paths>({ baseUrl: API_URL, credentials: 'include' });

vite.config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ export default defineConfig({
1313
server: {
1414
host: true,
1515
port: 3002,
16+
cors: true,
17+
proxy: {
18+
'/api': {
19+
target: 'http://localhost:3000',
20+
changeOrigin: true,
21+
secure: false,
22+
rewrite: (path) => path.replace(/^\/api/, ''),
23+
configure: (proxy, options) => {
24+
proxy.on('error', (err, req, res) => {
25+
console.log('proxy error', err);
26+
});
27+
proxy.on('proxyReq', (proxyReq, req, res) => {
28+
console.log('Sending Request to the Target:', req.method, req.url);
29+
});
30+
proxy.on('proxyRes', (proxyRes, req, res) => {
31+
console.log('Received Response from the Target:', proxyRes.statusCode);
32+
});
33+
},
34+
},
35+
'/secure': {
36+
target: 'http://localhost:3000',
37+
changeOrigin: true,
38+
secure: false,
39+
rewrite: (path) => path.replace(/^\/secure/, ''),
40+
configure: (proxy, options) => {
41+
proxy.on('error', (err, req, res) => {
42+
console.log('proxy error', err);
43+
});
44+
proxy.on('proxyReq', (proxyReq, req, res) => {
45+
console.log('Sending Request to the Target:', req.method, req.url);
46+
});
47+
proxy.on('proxyRes', (proxyRes, req, res) => {
48+
console.log('Received Response from the Target:', proxyRes.statusCode);
49+
});
50+
},
51+
}
52+
}
1653
},
1754
publicDir: 'public',
1855
build: {

0 commit comments

Comments
 (0)