Skip to content

Commit

Permalink
Fux Auth redirect bug when callGetUser fails
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorreem committed Aug 25, 2023
1 parent d2209e9 commit 67e1aa2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/activities.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ describe('A logged in user should be able to navigate to activities and do an ex

it('Should go to the activities page and click on an exercise', () => {
cy.get(`[qa-id=secondary-nav-activities-button]`).should('exist').click(); //navigate to activities

cy.get('h3').contains('Thought diaries').should('exist').click(); //check click first exercise exists and open it
// Default timeout is 4 seconds so extended to 8 to avoid racy tests
cy.get('h3', { timeout: 8000 }).contains('Thought diaries').should('exist').click(); //check click first exercise exists and open it

cy.get('.MuiCollapse-root.MuiCollapse-entered') //check the audio file exists in accordian
.should('exist')
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/grounding-exercises.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ describe('A logged in user should be able to navigate to grounding and do an exe

it('Should go to the grounding page and click on an exercise', () => {
cy.get(`[qa-id=secondary-nav-grounding-button]`).should('exist').click(); //navigate to grounding
// Extending timeout to ensure tests don't fail because of lazy loading
cy.get('h3', { timeout: 8000 }).contains('Visual breathing').should('exist').click(); //check visual breathing exercise exists and open it

cy.get('h3').contains('Visual breathing').should('exist').click(); //check visual breathing exercise exists and open it

cy.get('audio[src="https://a.storyblok.com/f/142459/x/add3c95f3c/visual-breathing-gif.m4a"]') //check the audio file exists in accordian
cy.get('audio') //check the audio file exists in accordian
.should('exist')
.invoke('attr', 'src')
.then((audiofile) => {
Expand Down
2 changes: 2 additions & 0 deletions guards/authGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export function AuthGuard({ children }: { children: JSX.Element }) {
logEvent(GET_USER_ERROR, { message: getErrorMessage(userResponse.error) }); // deprecated event
logEvent(GET_AUTH_USER_ERROR, { message: getErrorMessage(userResponse.error) });
}

auth.signOut();
await dispatch(clearPartnerAccessesSlice());
await dispatch(clearPartnerAdminSlice());
await dispatch(clearCoursesSlice());
Expand Down
2 changes: 2 additions & 0 deletions guards/publicPageDataWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export function PublicPageDataWrapper({ children }: { children: JSX.Element }) {
rollbar.error('LoadUserDataIfAvailable: get user error', userResponse.error);
logEvent(GET_AUTH_USER_ERROR, { message: getErrorMessage(userResponse.error) });
}

auth.signOut();
await dispatch(clearPartnerAccessesSlice());
await dispatch(clearPartnerAdminSlice());
await dispatch(clearCoursesSlice());
Expand Down
5 changes: 3 additions & 2 deletions pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ const Login: NextPage = () => {
const allPartnersContent = getAllPartnersContent();

useEffect(() => {
if (user.token) {
router.push('/courses'); // Redirect if the user is on the login page but is alredy logged in
// Redirect if the user is on the login page but is already logged in and their data has been retrieved from the backend
if (user.token && user.id) {
router.push('/courses');
}
}, [user.token]);

Expand Down

0 comments on commit 67e1aa2

Please sign in to comment.