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
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"@types/eslint": "^9.6.1",
"@types/eslint__js": "9.14.0",
"@types/lodash": "4.17.16",
"@types/react": "19.1.2",
"@types/react-dom": "19.1.3",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.3",
"@types/react-router": "5.1.20",
"@types/react-router-dom": "5.3.3",
"@types/uuid": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/common/api/useGetCurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useGetCurrentUser = () => {
username: cognitoUser.username || '',
attributes: {
// Extract whatever attributes are available from the user object
email: cognitoUser.signInDetails?.loginId || '',
email: cognitoUser.attributes.email || '',
},
};

Expand Down
47 changes: 31 additions & 16 deletions frontend/src/common/hooks/__tests__/useAuthOperations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import * as AuthErrorUtils from 'common/utils/auth-errors';
import { AuthError, UserTokens } from 'common/models/auth';
import { CognitoUser } from 'common/models/user';
import * as UserMapper from 'common/utils/user-mapper';
import {
ConfirmSignUpCommandOutput,
ResendConfirmationCodeCommandOutput,
SignUpCommandOutput,
} from '@aws-sdk/client-cognito-identity-provider';

// Mock the DirectCognitoAuthService
vi.mock('common/services/auth/direct-cognito-auth-service', () => ({
Expand Down Expand Up @@ -110,12 +115,11 @@ describe('useAuthOperations', () => {

describe('signUp', () => {
it('should call DirectCognitoAuthService.signUp with correct parameters', async () => {
const mockSignUpResult = {
username: '[email protected]',
userConfirmed: false,
isSignUpComplete: false,
nextStep: { signUpStep: 'CONFIRM_SIGN_UP' },
} as unknown;
const mockSignUpResult: SignUpCommandOutput = {
UserConfirmed: false,
UserSub: 'test-sub',
$metadata: {},
};

vi.mocked(DirectCognitoAuthService.signUp).mockResolvedValueOnce(mockSignUpResult);

Expand Down Expand Up @@ -174,10 +178,9 @@ describe('useAuthOperations', () => {

describe('confirmSignUp', () => {
it('should call DirectCognitoAuthService.confirmSignUp with correct parameters', async () => {
const mockConfirmResult = {
isSignUpComplete: true,
nextStep: { signUpStep: 'DONE' },
} as unknown;
const mockConfirmResult: ConfirmSignUpCommandOutput = {
$metadata: {},
};

vi.mocked(DirectCognitoAuthService.confirmSignUp).mockResolvedValueOnce(mockConfirmResult);

Expand All @@ -198,11 +201,14 @@ describe('useAuthOperations', () => {

describe('resendConfirmationCode', () => {
it('should call DirectCognitoAuthService.resendConfirmationCode with correct email', async () => {
const mockResult = {
deliveryMedium: 'EMAIL',
destination: '[email protected]',
attributeName: 'email',
} as unknown;
const mockResult: ResendConfirmationCodeCommandOutput = {
CodeDeliveryDetails: {
AttributeName: 'email',
DeliveryMedium: 'EMAIL',
Destination: '[email protected]',
},
$metadata: {},
};

vi.mocked(DirectCognitoAuthService.resendConfirmationCode).mockResolvedValueOnce(mockResult);

Expand Down Expand Up @@ -231,7 +237,16 @@ describe('useAuthOperations', () => {
const mockUser = { id: 'mock-id', username: '[email protected]', email: '[email protected]' };

// First, we need to set up the user by simulating a successful sign-in
vi.mocked(DirectCognitoAuthService.signIn).mockResolvedValueOnce({});
const mockTokens: UserTokens = {
access_token: 'token',
id_token: 'id-token',
refresh_token: 'refresh-token',
token_type: 'bearer',
expires_in: 3600,
expires_at: new Date().toISOString(),
};

vi.mocked(DirectCognitoAuthService.signIn).mockResolvedValueOnce(mockTokens);
vi.mocked(UserMapper.mapCognitoUserToAppUser).mockReturnValueOnce(mockUser as CognitoUser);

await act(async () => {
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/common/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export type User = {
company: Company;
};

/**
* Login details from Cognito
*/
export type SignInDetails = {
loginId?: string;
// Add any other properties that might be needed
};

/**
* Cognito User type aligned with AWS Cognito attributes
*/
Expand Down Expand Up @@ -63,4 +71,6 @@ export type CognitoUser = {
createdAt?: string;
// Updated date
updatedAt?: string;
// Sign-in details (optional)
signInDetails?: SignInDetails;
};
2 changes: 1 addition & 1 deletion frontend/src/common/providers/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const AuthProvider = ({ children }: PropsWithChildren): JSX.Element => {
const userData = {
username: currentUser.username || '',
attributes: {
email: currentUser.signInDetails?.loginId || '',
email: currentUser.attributes.email || '',
given_name: currentUser.username?.split('@')[0] || '',
family_name: '',
},
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/types/react.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="react" />

declare namespace JSX {
// Added a property to avoid the "interface declaring no members is equivalent to its supertype" error
interface Element
extends React.ReactElement<React.ComponentProps<React.ElementType>, React.ElementType> {
_jsx_element?: true;
}
interface IntrinsicElements {
[elemName: string]: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
}
}
2 changes: 1 addition & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["eslint"],
"types": ["eslint", "react", "react-dom"],

/* Absolute imports */
"paths": {
Expand Down