Skip to content

Commit 5960c22

Browse files
committed
Revert "Update UserContext to use util parseJwt"
This reverts commit fc9db08.
1 parent fc9db08 commit 5960c22

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

frontend/src/contexts/UserContext.tsx

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

3-
import { parseJwt } from "@/lib/auth";
43
import {
54
AccessToken,
65
AccessTokenPayload,
@@ -35,3 +34,17 @@ export function UserProvider({ children }: PropsWithChildren) {
3534
export function useUser() {
3635
return useContext(UserContext);
3736
}
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)