Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 6144958

Browse files
Oauth Changes
1 parent b844f47 commit 6144958

28 files changed

+1274
-423
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
"@mantine/prism": "^6.0.15",
2323
"@monaco-editor/react": "^4.5.1",
2424
"@tabler/icons-react": "^2.23.0",
25+
"@types/js-cookie": "^3.0.3",
2526
"axios": "^1.4.0",
2627
"dayjs": "^1.11.8",
2728
"http-status-codes": "^2.2.0",
2829
"immer": "^10.0.2",
30+
"js-cookie": "^3.0.5",
2931
"just-compare": "^2.3.0",
3032
"ms": "^2.1.3",
3133
"react": "^18.2.0",

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

signatures/version1/cla.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
"created_at": "2023-07-24T18:47:46Z",
3232
"repoId": 523035254,
3333
"pullRequestNo": 91
34+
},
35+
{
36+
"name": "aldrinjenson",
37+
"id": 53407417,
38+
"comment_id": 1709632333,
39+
"created_at": "2023-09-07T07:38:23Z",
40+
"repoId": 523035254,
41+
"pullRequestNo": 129
3442
}
3543
]
3644
}

src/api/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Axios } from './axios';
2-
import { LOG_STREAM_LIST_URL } from './constants';
2+
import { LOGIN_URL } from './constants';
3+
34

45
export const loginIn = (username: string, password: string) => {
56
const credentials = btoa(`${username}:${password}`);
67

7-
return Axios().get(LOG_STREAM_LIST_URL, {
8+
return Axios().get(LOGIN_URL, {
89
headers: {
910
Authorization: `Basic ${credentials}`,
1011
},

src/api/axios.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ import axios from 'axios';
22

33
const baseURL = import.meta.env.VITE_PARSEABLE_URL ?? '/';
44

5-
const instance = axios.create({ baseURL, validateStatus: () => true });
5+
const instance = axios.create({ baseURL, validateStatus: () => true, withCredentials: true });
66

77
instance.interceptors.request.use(
88
(request) => {
9-
const credentials = localStorage.getItem('credentials');
10-
11-
if (credentials) {
12-
const Authorization = credentials ? `Basic ${credentials}` : null;
13-
14-
request.headers.Authorization = Authorization;
15-
}
16-
179
return request;
1810
},
1911
(error) => {

src/api/constants.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const API_V1 = 'api/v1';
2-
3-
2+
// const baseURL = process.env.REACT_APP_API_URL || '/';
43
// Streams Management
54
export const LOG_STREAM_LIST_URL = `${API_V1}/logstream`;
65
export const LOG_STREAMS_SCHEMA_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/schema`;
@@ -17,4 +16,14 @@ export const ABOUT_URL = `${API_V1}/about`;
1716
export const USERS_LIST_URL = `${API_V1}/user`;
1817
export const USER_URL = (username: string) => `${USERS_LIST_URL}/${username}`;
1918
export const USER_ROLES_URL = (username: string) => `${USER_URL(username)}/role`;
20-
export const USER_PASSWORD_URL = (username: string) => `${USER_URL(username)}/generate-new-password`;
19+
export const USER_PASSWORD_URL = (username: string) => `${USER_URL(username)}/generate-new-password`;
20+
21+
22+
// Roles Management
23+
export const ROLES_LIST_URL = `${API_V1}/role`;
24+
export const ROLE_URL = (roleName: string) => `${ROLES_LIST_URL}/${roleName}`;
25+
26+
27+
//USERS LOGIN
28+
29+
export const LOGIN_URL = `${API_V1}/o/login?redirect=${window.location.origin}`;

src/api/roles.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Axios } from "./axios";
2+
import { ROLE_URL, ROLES_LIST_URL } from "./constants";
3+
4+
export const getRoles = () => {
5+
return Axios().get(ROLES_LIST_URL);
6+
}
7+
8+
export const deleteRole = (roleName: string) => {
9+
return Axios().delete(ROLE_URL(roleName));
10+
}
11+
12+
export const putRole = (roleName: string, privilege: object[]) => {
13+
return Axios().put(ROLE_URL(roleName), privilege);
14+
}
15+
16+
export const getRole = (roleName: string) => {
17+
return Axios().get(ROLE_URL(roleName));
18+
}

src/components/Header/SubHeader.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import TimeRange from './TimeRange';
88
import { useLogQueryStyles } from './styles';
99
import ReloadUser from './ReloadUser';
1010
import DocsUser from './UserDocs';
11-
import CreateUser from './CreateUser';
12-
// import LimitLog from './LimitLogs';
11+
1312

1413
export const StatsHeader: FC = () => {
1514
const { classes } = useLogQueryStyles();
@@ -110,7 +109,7 @@ export const UsersManagementHeader: FC = () => {
110109
<Box className={innerContainer}>
111110
<ReloadUser />
112111
<DocsUser />
113-
<CreateUser />
112+
{/* <CreateUser /> */}
114113
</Box>
115114
</Box>
116115
</Box>

src/components/Mantine/theme.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSObject, MantineThemeOverride } from '@mantine/core';
1+
import { type CSSObject, type MantineThemeOverride } from '@mantine/core';
22
import { heights, widths, sizing } from './sizing';
33

44
const globalStyles = (): CSSObject => {
@@ -235,5 +235,17 @@ export const theme: MantineThemeOverride = {
235235
};
236236
}
237237
},
238+
239+
PasswordInput: {
240+
styles: ({ colors }) => {
241+
return {
242+
input: {
243+
border: `${sizing.px} ${colors.gray[2]} solid`,
244+
borderRadius: 'md',
245+
246+
},
247+
};
248+
}
249+
}
238250
},
239251
};

src/components/Navbar/index.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@ import {
1616
} from '@tabler/icons-react';
1717
import { FC, useEffect } from 'react';
1818
import { useNavbarStyles } from './styles';
19-
import { useLocation, useParams } from 'react-router-dom';
19+
import { useLocation, useParams } from 'react-router-dom';
2020
import { useGetLogStreamList } from '@/hooks/useGetLogStreamList';
2121
import { notifications } from '@mantine/notifications';
2222
import { useNavigate } from 'react-router-dom';
2323
import { DEFAULT_FIXED_DURATIONS, useHeaderContext } from '@/layouts/MainLayout/Context';
2424
import useMountedState from '@/hooks/useMountedState';
2525
import dayjs from 'dayjs';
26-
import { useDisclosure, useLocalStorage } from '@mantine/hooks';
27-
import { LOGIN_ROUTE, USERS_MANAGEMENT_ROUTE } from '@/constants/routes';
26+
import { useDisclosure } from '@mantine/hooks';
27+
import { USERS_MANAGEMENT_ROUTE } from '@/constants/routes';
2828
import { useDeleteLogStream } from '@/hooks/useDeleteLogStream';
2929
import InfoModal from './infoModal';
3030
import { useGetUserRole } from '@/hooks/useGetUserRoles';
3131
import { getStreamsSepcificAccess, getUserSepcificStreams } from './rolesHandler';
3232
import { LogStreamData } from '@/@types/parseable/api/stream';
33+
import Cookies from 'js-cookie';
34+
const baseURL = import.meta.env.VITE_PARSEABLE_URL ?? '/';
3335

3436
const links = [
3537
{ icon: IconZoomCode, label: 'Query', pathname: '/query', requiredAccess: ['Query', 'GetSchema'] },
@@ -45,9 +47,7 @@ const Navbar: FC<NavbarProps> = (props) => {
4547
const { streamName } = useParams();
4648
const location = useLocation();
4749

48-
const [username] = useLocalStorage({ key: 'username', getInitialValueInEffect: false });
49-
const [, , removeCredentials] = useLocalStorage({ key: 'credentials' });
50-
const [, , removeUsername] = useLocalStorage({ key: 'username' });
50+
const username = Cookies.get('username')
5151

5252
const {
5353
state: { subNavbarTogle },
@@ -75,14 +75,10 @@ const Navbar: FC<NavbarProps> = (props) => {
7575
}, [subNavbarTogle.get()]);
7676

7777
const onSignOut = () => {
78-
removeCredentials();
79-
removeUsername();
80-
navigate(
81-
{
82-
pathname: LOGIN_ROUTE,
83-
},
84-
{ replace: true },
85-
);
78+
Cookies.remove('session');
79+
Cookies.remove('username');
80+
81+
window.location.href=`${baseURL}api/v1/o/logout?redirect=${window.location.origin}/login`;
8682
};
8783

8884
const {
@@ -172,7 +168,6 @@ const Navbar: FC<NavbarProps> = (props) => {
172168
}
173169
}, [deleteData]);
174170

175-
//isAdmin
176171
const { data: roles, getRoles, resetData } = useGetUserRole();
177172
useEffect(() => {
178173
if (username) {
@@ -184,8 +179,8 @@ const Navbar: FC<NavbarProps> = (props) => {
184179
}, [username]);
185180

186181
useEffect(() => {
187-
if (streams && streams.length > 0 && roles && roles.length > 0) {
188-
const userStreams = getUserSepcificStreams(roles, streams as any);
182+
if(streams && streams.length > 0 && roles){
183+
const userStreams = getUserSepcificStreams(roles,streams as any);
189184
setUserSepecficStreams(userStreams as any);
190185
}
191186
}, [roles, streams]);

0 commit comments

Comments
 (0)