Skip to content

Commit 9097ba3

Browse files
committed
fix token expiration issue, styling enhancements
1 parent 0f893c4 commit 9097ba3

File tree

8 files changed

+60
-18
lines changed

8 files changed

+60
-18
lines changed

applications/osb-portal/src/components/common/OSBPagination.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const StyledPagination = styled(Pagination)(() => ({
2424
},
2525
}));
2626

27-
export default (props: OSBPaginationProps) => {
27+
export const OSBPagination = (props: OSBPaginationProps) => {
2828
return (
2929
<StyledPagination
3030
sx={{ borderTop: props?.removeTopBorder ? 0 : `1px solid ${lineColor}` }}
@@ -36,3 +36,5 @@ export default (props: OSBPaginationProps) => {
3636
/>
3737
);
3838
};
39+
40+
export default OSBPagination;

applications/osb-portal/src/components/common/RepositoriesWorkspacesSearchField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { debounce } from "lodash";
1414

1515
const StyledTextField = styled(TextField)({
1616
backgroundColor: bgRegular,
17-
padding: 1,
17+
padding: "0.75rem",
1818
marginRight: "0.286rem",
1919
"& .MuiSvgIcon-root": {
2020
width: "1.25rem",

applications/osb-portal/src/components/common/SearchFilterReposWorkspaces.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const StyledLabel = styled(Typography)({
4848
color: bgInputs,
4949
fontWeight: 700,
5050
fontSize: ".88rem",
51-
marginBottom: 1,
51+
marginBottom: "0.75rem",
5252
display: "inline-block",
5353
});
5454

@@ -68,7 +68,7 @@ const StyledPopover = styled(Popover)({
6868
paddingBottom: 0,
6969
marginBottom: ".88rem",
7070
"& .MuiSvgIcon-root": {
71-
marginLeft: 1,
71+
marginLeft: "0.75rem",
7272
color: paragraph,
7373
},
7474
"& .MuiInputBase-root": {

applications/osb-portal/src/components/common/ThumbnailUploadArea.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export const StyledDropZoneBox = styled(Box)({
1919
color: bgInputs,
2020
border: `2px dashed ${bgInputs}`,
2121
borderRadius: 5,
22-
padding: 4,
22+
padding: "2rem",
2323
"& .MuiTypography-subtitle2": {
24-
marginTop: 1,
25-
marginBottom: 2,
24+
marginTop: "0.75rem",
25+
marginBottom: "1rem",
2626
},
2727
"& .MuiButton-outlined": {
2828
margin: "0 auto",
@@ -43,7 +43,7 @@ export const StyledImagePreviewSection = styled("section")(() => ({
4343
flex: 1,
4444
}));
4545

46-
export const dropAreaStyle = (error: any) => ({
46+
const dropAreaStyle = (error: any) => ({
4747
flex: 1,
4848
display: "flex",
4949
alignItems: "center",

applications/osb-portal/src/components/styled/FormLabel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import styled from "@mui/system/styled";
88

99
export const StyledLabel = styled((props: any) => (
1010
<Typography {...props} component="label" />
11-
))(({ theme }) => ({
11+
))({
1212
fontWeight: "bold",
1313
lineHeight: "2em",
1414
fontSize: "0.8rem",
15-
}));
15+
});
1616

1717
export default StyledLabel;

applications/osb-portal/src/components/workspace/WorkspaceEditor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import "react-markdown-editor-lite/lib/index.css";
2424

2525
//style
2626
import styled from "@mui/system/styled";
27-
import { bgLight, radius, gutter, bgInputs, bgDarkest } from "../../theme";
27+
import { bgLight } from "../../theme";
2828

2929
//types
3030
import { Workspace } from "../../types/workspace";
@@ -39,7 +39,7 @@ import { readFile } from "../../utils";
3939

4040

4141

42-
const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({
42+
const StyledAutocomplete = styled(Autocomplete)({
4343
"& .MuiChip-root": {
4444
backgroundColor: bgLight,
4545
},
@@ -51,7 +51,7 @@ const StyledAutocomplete = styled(Autocomplete)(({ theme }) => ({
5151
border: "0 !important",
5252
},
5353
},
54-
}));
54+
});
5555

5656
interface WorkspaceEditProps {
5757
workspace: Workspace;

applications/osb-portal/src/pages/Repositories/RepositoriesCards.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import RepositoryActionsMenu from "../../components/repository/RepositoryActions
3434
import CardTitle from "../../components/styled/CardTitle";
3535
import Grid from "@mui/material/Grid";
3636
import CardFooter from "../../components/styled/CardFooter";
37-
import { useNavigate } from "react-router-dom";
38-
import { refreshRepositories } from "../../store/actions/repositories";
3937

4038
interface RepositoriesProps {
4139
repositories: OSBRepository[];
@@ -45,15 +43,15 @@ interface RepositoriesProps {
4543
refreshRepositories: () => void;
4644
}
4745

48-
export const StyledContextChip = styled(Chip)((theme) => ({
46+
export const StyledContextChip = styled(Chip)({
4947
background: chipBg,
5048
borderRadius: "16px",
5149
maxWidth: "5.5rem",
5250
overflow: "hidden",
5351
color: chipTextColor,
5452
fontSize: "0.857rem",
5553
padding: "0.143rem",
56-
}));
54+
});
5755

5856
export const RepositoriesListCards = (props: RepositoriesProps) => {
5957
const { repositories, loading, handleRepositoryClick, refreshRepositories } =

applications/osb-portal/src/service/UserService.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ function getCookie(name): string {
6464
return null;
6565
}
6666

67+
function deleteCookie(name: string) {
68+
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=${getBaseDomain()}`;
69+
}
70+
6771
function parseJwt(token: string) {
6872
if (!token) {
6973
return null;
@@ -84,7 +88,45 @@ function parseJwt(token: string) {
8488
}
8589

8690
export function getToken(): string {
87-
return getCookie("kc-access");
91+
const token = getCookie("kc-access");
92+
93+
if (!token) {
94+
return null;
95+
}
96+
97+
try {
98+
// Use the existing parseJwt function to decode the token
99+
const decoded = parseJwt(token);
100+
101+
if (!decoded || !decoded.exp) {
102+
// If token doesn't have expiration field, delete cookies (only if not localhost)
103+
if (!window.location.hostname.includes('localhost')) {
104+
deleteCookie("kc-access");
105+
deleteCookie("accessToken");
106+
}
107+
return null;
108+
}
109+
110+
// Check if token is expired (exp is in seconds, Date.now() is in milliseconds)
111+
const currentTime = Math.floor(Date.now() / 1000);
112+
if (decoded.exp < currentTime) {
113+
// Token is expired, delete cookies (only if not localhost)
114+
if (!window.location.hostname.includes('localhost')) {
115+
deleteCookie("kc-access");
116+
deleteCookie("accessToken");
117+
}
118+
return null;
119+
}
120+
121+
return token;
122+
} catch {
123+
// If decoding fails, delete the cookies (only if not localhost)
124+
if (!window.location.hostname.includes('localhost')) {
125+
deleteCookie("kc-access");
126+
deleteCookie("accessToken");
127+
}
128+
return null;
129+
}
88130
}
89131

90132
export function initUser(): UserInfo {

0 commit comments

Comments
 (0)