File tree Expand file tree Collapse file tree 3 files changed +58
-27
lines changed Expand file tree Collapse file tree 3 files changed +58
-27
lines changed Original file line number Diff line number Diff line change @@ -2,21 +2,28 @@ import React from 'react';
2
2
import ReactDOM from 'react-dom' ;
3
3
import { createBrowserHistory } from 'history' ;
4
4
import { BrowserRouter as Router , Route , Routes , Navigate } from 'react-router-dom' ;
5
+ import { AuthProvider } from './ui/auth/AuthProvider' ;
5
6
6
7
// core components
7
8
import Admin from './ui/layouts/Admin' ;
8
9
import Login from './ui/views/Login/Login' ;
9
10
import './ui/assets/css/material-dashboard-react.css' ;
11
+ import NotAuthorized from './ui/views/Extras/NotAuthorized' ;
12
+ import NotFound from './ui/views/Extras/NotFound' ;
10
13
11
14
const hist = createBrowserHistory ( ) ;
12
15
13
16
ReactDOM . render (
14
- < Router history = { hist } >
15
- < Routes >
16
- < Route exact path = '/admin/*' element = { < Admin /> } />
17
- < Route exact path = '/login' element = { < Login /> } />
18
- < Route exact path = '/' element = { < Navigate from = '/' to = '/admin/repo' /> } />
19
- </ Routes >
20
- </ Router > ,
17
+ < AuthProvider >
18
+ < Router history = { hist } >
19
+ < Routes >
20
+ < Route exact path = '/admin/*' element = { < Admin /> } />
21
+ < Route exact path = '/login' element = { < Login /> } />
22
+ < Route exact path = '/not-authorized' element = { < NotAuthorized /> } />
23
+ < Route exact path = '/' element = { < Navigate from = '/' to = '/admin/repo' /> } />
24
+ < Route path = '*' element = { < NotFound /> } />
25
+ </ Routes >
26
+ </ Router >
27
+ </ AuthProvider > ,
21
28
document . getElementById ( 'root' ) ,
22
29
) ;
Original file line number Diff line number Diff line change 16
16
17
17
*/
18
18
19
+ import React from 'react' ;
20
+ import PrivateRoute from './ui/components/PrivateRoute/PrivateRoute' ;
19
21
import Person from '@material-ui/icons/Person' ;
20
22
import OpenPushRequests from './ui/views/OpenPushRequests/OpenPushRequests' ;
21
23
import PushDetails from './ui/views/PushDetails/PushDetails' ;
@@ -33,58 +35,58 @@ const dashboardRoutes = [
33
35
path : '/repo' ,
34
36
name : 'Repositories' ,
35
37
icon : RepoIcon ,
36
- component : RepoList ,
38
+ component : ( props ) => < PrivateRoute component = { RepoList } /> ,
37
39
layout : '/admin' ,
38
40
visible : true ,
39
41
} ,
42
+ {
43
+ path : '/repo/:id' ,
44
+ name : 'Repo Details' ,
45
+ icon : Person ,
46
+ component : ( props ) => < PrivateRoute component = { RepoDetails } /> ,
47
+ layout : '/admin' ,
48
+ visible : false ,
49
+ } ,
40
50
{
41
51
path : '/push' ,
42
52
name : 'Dashboard' ,
43
53
icon : Dashboard ,
44
- component : OpenPushRequests ,
54
+ component : ( props ) => < PrivateRoute component = { OpenPushRequests } /> ,
45
55
layout : '/admin' ,
46
56
visible : true ,
47
57
} ,
48
58
{
49
59
path : '/push/:id' ,
50
60
name : 'Open Push Requests' ,
51
61
icon : Person ,
52
- component : PushDetails ,
62
+ component : ( props ) => < PrivateRoute component = { PushDetails } /> ,
53
63
layout : '/admin' ,
54
64
visible : false ,
55
65
} ,
56
66
{
57
67
path : '/profile' ,
58
68
name : 'My Account' ,
59
69
icon : AccountCircle ,
60
- component : User ,
70
+ component : ( props ) => < PrivateRoute component = { User } /> ,
61
71
layout : '/admin' ,
62
72
visible : true ,
63
73
} ,
64
74
{
65
- path : '/user/:id ' ,
66
- name : 'User ' ,
67
- icon : Person ,
68
- component : User ,
75
+ path : '/user' ,
76
+ name : 'Users ' ,
77
+ icon : Group ,
78
+ component : ( props ) => < PrivateRoute adminOnly component = { UserList } /> ,
69
79
layout : '/admin' ,
70
- visible : false ,
80
+ visible : true ,
71
81
} ,
72
82
{
73
- path : '/repo /:id' ,
74
- name : 'Repo Details ' ,
83
+ path : '/user /:id' ,
84
+ name : 'User ' ,
75
85
icon : Person ,
76
- component : RepoDetails ,
86
+ component : ( props ) => < PrivateRoute adminOnly component = { User } /> ,
77
87
layout : '/admin' ,
78
88
visible : false ,
79
89
} ,
80
- {
81
- path : '/user' ,
82
- name : 'Users' ,
83
- icon : Group ,
84
- component : UserList ,
85
- layout : '/admin' ,
86
- visible : true ,
87
- } ,
88
90
] ;
89
91
90
92
export default dashboardRoutes ;
Original file line number Diff line number Diff line change
1
+ const baseUrl = import . meta. env . VITE_API_URI
2
+ ? `${ import . meta. env . VITE_API_URI } `
3
+ : `${ location . origin } ` ;
4
+
5
+ /**
6
+ * Gets the current user's information
7
+ * @return {Promise<Object> } The user's information
8
+ */
9
+ export const getUserInfo = async ( ) => {
10
+ try {
11
+ const response = await fetch ( `${ baseUrl } /api/auth/me` , {
12
+ credentials : 'include' , // Sends cookies
13
+ } ) ;
14
+
15
+ if ( ! response . ok ) throw new Error ( `Failed to fetch user info: ${ response . statusText } ` ) ;
16
+
17
+ return await response . json ( ) ;
18
+ } catch ( error ) {
19
+ console . error ( 'Error fetching user info:' , error ) ;
20
+ return null ;
21
+ }
22
+ } ;
You can’t perform that action at this time.
0 commit comments