Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/demo/demoAuthClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('demoAuthClient', () => {
await expect(auth.getCurrentUser()).rejects.toThrow();
});

it("fetchAuthSession resolves cognito:groups from the stored user's role", async () => {
it("fetchAuthSession resolves groups from the stored user's role", async () => {
authGetStoredAuth.mockReturnValue({
accessToken: 'a',
refreshToken: 'r',
Expand All @@ -142,7 +142,7 @@ describe('demoAuthClient', () => {

const session = await auth.fetchAuthSession();

expect(session.tokens?.accessToken?.payload['cognito:groups']).toEqual(['admin']);
expect(session.groups).toEqual(['admin']);
});

it('fetchAuthSession resolves no admin group for a non-admin user', async () => {
Expand All @@ -155,7 +155,7 @@ describe('demoAuthClient', () => {

const session = await auth.fetchAuthSession();

expect(session.tokens?.accessToken?.payload['cognito:groups']).toEqual([]);
expect(session.groups).toEqual([]);
});

it('signOut delegates to authClient.logout', async () => {
Expand Down
15 changes: 6 additions & 9 deletions src/demo/demoAuthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
* the server-backed `../api/authClient` (POST /auth/* on the Express/Prisma
* server — see server/src/auth/routes.js).
*
* The shapes below (nextStep, signInStep, etc.) are a holdover from this
* module's origin as a drop-in replacement for a Cognito-flavored auth SDK;
* kept as local types since authSlice, Login, and Dashboard already consume
* them.
* The shapes below (nextStep, signInStep, etc.) are a minimal auth-session
* stub for demo mode; kept as local types since authSlice, Login, and
* Dashboard already consume them.
*
* The API has no equivalent of email-verification or password-reset flows
* (v1 has none). Where the contract expects a `nextStep`, those functions
Expand Down Expand Up @@ -79,7 +78,7 @@ interface ConfirmResetPasswordInput {
}

interface AuthSession {
tokens: { accessToken: { payload: { 'cognito:groups': string[] } } };
groups: string[];
}

let demoSignedIn = false;
Expand Down Expand Up @@ -177,13 +176,11 @@ export async function getCurrentUser(): Promise<AuthUser> {

export async function fetchAuthSession(): Promise<AuthSession> {
if (isDemoMode) {
return { tokens: { accessToken: { payload: { 'cognito:groups': ['admin'] } } } };
return { groups: ['admin'] };
}
const role = authClient.getStoredAuth()?.user.role;
const groups = role === 'admin' ? ['admin'] : [];
return {
tokens: { accessToken: { payload: { 'cognito:groups': groups } } },
};
return { groups };
}

export async function signOut(): Promise<void> {
Expand Down
5 changes: 2 additions & 3 deletions src/features/authSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export const checkSession = createAsyncThunk(
const user = await getCurrentUser();
const session = await fetchAuthSession();

// Check if user is admin (based on Cognito groups or custom attribute)
const groups = session.tokens?.accessToken?.payload['cognito:groups'] as string[] | undefined;
const isAdmin = groups?.includes('admin') ?? false;
// Check if user is admin (based on session groups or custom attribute)
const isAdmin = session.groups?.includes('admin') ?? false;

return {
email: user.signInDetails?.loginId || user.username,
Expand Down
Loading