Skip to content

Commit fc9db08

Browse files
committed
Update UserContext to use util parseJwt
1 parent 57755c0 commit fc9db08

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

frontend/src/contexts/UserContext.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { parseJwt } from "@/lib/auth";
34
import {
45
AccessToken,
56
AccessTokenPayload,
@@ -34,17 +35,3 @@ export function UserProvider({ children }: PropsWithChildren) {
3435
export function useUser() {
3536
return useContext(UserContext);
3637
}
37-
38-
function parseJwt(token: AccessToken): AccessTokenPayload {
39-
const base64Url = token.split(".")[1];
40-
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
41-
const jsonPayload = decodeURIComponent(
42-
atob(base64)
43-
.split("")
44-
.map((c) => {
45-
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
46-
})
47-
.join("")
48-
);
49-
return AccessTokenPayloadSchema.parse(JSON.parse(jsonPayload));
50-
}

0 commit comments

Comments
 (0)