Skip to content

Commit d1e5df4

Browse files
committed
add payload to auth
1 parent 57ebc73 commit d1e5df4

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

apps/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"esbuild-wasm": "catalog:",
2626
"immer": "^10.1.1",
2727
"jszip": "^3.10.1",
28+
"jwt-decode": "^4.0.0",
2829
"lodash-es": "workspace:lodash-es__4.x@*",
2930
"lucide-react": "^0.503.0",
3031
"lz-string": "^1.5.0",
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { jwtDecode } from 'jwt-decode';
2+
13
import type { AuthSlice, SliceCreator } from '../types';
24

35
export const createAuthSlice: SliceCreator<AuthSlice> = (set) => ({
4-
accessToken: null,
5-
setAccessToken: (accessToken) => {
6+
auth: null,
7+
login: (accessToken) => {
68
set((state) => {
7-
state.accessToken = accessToken;
9+
state.auth = {
10+
accessToken,
11+
payload: jwtDecode(accessToken)
12+
};
813
});
914
}
1015
});

apps/playground/src/store/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { JwtPayload } from 'jwt-decode';
12
import type { Simplify } from 'type-fest';
23
import type { StateCreator } from 'zustand';
34

@@ -35,8 +36,11 @@ export type TranspilerSlice = {
3536
};
3637

3738
export type AuthSlice = {
38-
accessToken: null | string;
39-
setAccessToken: (accessToken: null | string) => void;
39+
auth: null | {
40+
accessToken: string;
41+
payload: JwtPayload;
42+
};
43+
login: (accessToken: string) => void;
4044
};
4145

4246
export type EditorState = {

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)