Skip to content

Commit 0ce3daa

Browse files
committed
add window.__PLAYWRIGHT_ACCESS_TOKEN__
1 parent c8a7147 commit 0ce3daa

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

apps/web/src/store/slices/auth.slice.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ import { jwtDecode } from 'jwt-decode';
55

66
import type { AuthSlice, SliceCreator } from '../types';
77

8-
export const createAuthSlice: SliceCreator<AuthSlice> = (set) => ({
9-
accessToken: null,
10-
changeGroup: (group) => {
11-
set({ currentGroup: group, currentSession: null });
12-
},
13-
currentGroup: null,
14-
currentUser: null,
15-
login: (accessToken) => {
16-
const { groups, permissions, ...rest } = jwtDecode<TokenPayload>(accessToken);
17-
const ability = createMongoAbility<PureAbility<[AppAction, AppSubjectName], any>>(permissions);
18-
set({
19-
accessToken,
20-
currentGroup: groups[0],
21-
currentUser: { ability, groups, ...rest }
22-
});
23-
},
24-
logout: () => {
25-
window.location.reload();
26-
}
27-
});
8+
export const createAuthSlice: SliceCreator<AuthSlice> = (set) => {
9+
return {
10+
accessToken: window.__PLAYWRIGHT_ACCESS_TOKEN__ ?? null,
11+
changeGroup: (group) => {
12+
set({ currentGroup: group, currentSession: null });
13+
},
14+
currentGroup: null,
15+
currentUser: null,
16+
login: (accessToken) => {
17+
const { groups, permissions, ...rest } = jwtDecode<TokenPayload>(accessToken);
18+
const ability = createMongoAbility<PureAbility<[AppAction, AppSubjectName], any>>(permissions);
19+
set({
20+
accessToken,
21+
currentGroup: groups[0],
22+
currentUser: { ability, groups, ...rest }
23+
});
24+
},
25+
logout: () => {
26+
window.location.reload();
27+
}
28+
};
29+
};

apps/web/src/vite-env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ interface ImportMeta {
2727
readonly env: ImportMetaEnv;
2828
}
2929

30+
interface Window {
31+
__PLAYWRIGHT_ACCESS_TOKEN__?: string;
32+
}
33+
3034
declare const __RELEASE__: import('@opendatacapture/schemas/setup').ReleaseInfo;

testing/e2e/src/helpers/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ declare global {
1111
ADMIN_USERNAME: string;
1212
}
1313
}
14+
interface Window {
15+
__PLAYWRIGHT_ACCESS_TOKEN__?: string;
16+
}
1417
}
1518

1619
export type BrowserTarget = 'Desktop Chrome' | 'Desktop Firefox';

0 commit comments

Comments
 (0)