We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc9db08 commit 5960c22Copy full SHA for 5960c22
frontend/src/contexts/UserContext.tsx
@@ -1,6 +1,5 @@
1
"use client";
2
3
-import { parseJwt } from "@/lib/auth";
4
import {
5
AccessToken,
6
AccessTokenPayload,
@@ -35,3 +34,17 @@ export function UserProvider({ children }: PropsWithChildren) {
35
34
export function useUser() {
36
return useContext(UserContext);
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