mwill8886
06/21/2022, 8:43 PMdoesSessionExist
and isEmailVerified
from supertokens-auth-react
to check on protected pages, if they do not have a session they get redirected and if the email is not verified they get redirected. My issue comes when I'm testing my pages with Cypress. Whenever Cypress loads up pages it fires off a request to /auth/session/refresh
. If i just have Cypress set a cookie sIRTFrontend: remove
it gets passed that request. But when It gets to my protected route wrapper and checks for doesSessionExist
it will fail. My questions are:
1: How should we be mocking either a response for /auth/session/refresh
or setting those cookies?
2: How should we be mocking the cookies so doesSessionExist
actually returns true?
As of now I can set some cookies for doesSessionExist
with false data that just returns true but i cannot use that in conjunction with my solution for bypassing /auth/session/refresh
rp_st
06/22/2022, 5:33 AMrp_st
06/22/2022, 5:40 AM{"uid":"14f5181b-08ce-497b-8788-96fba548f9b0","ate":1655879840417,"up":{}}
- id-refresh-token (some random string)
The above will result in the frontend saying that the session exists.
You will also need to modify the getSession
recipe function to return a session object when the input is your mocked sAccessToken.
Once you do both of the above, session testing should work.csjaction
06/27/2022, 8:28 PMrp_st
06/28/2022, 4:02 AMcsjaction
06/28/2022, 5:07 PMrp_st
06/28/2022, 5:08 PMcsjaction
07/07/2022, 6:17 PMCypress.Commands.add('interceptApiAuthRefresh', (statusAndHeaders = { statusCode: 200, headers: null }) => {
let { statusCode, headers } = statusAndHeaders
if (headers === null) {
const obj = {
uid: '62e9e7d8-d87d-4a6d-934d-849b10efd57a',
ate: Date.now() + 600_000,
up: {
userId: 'cl4j22f2c0020ldxgbx60v8s6',
userPermanentId: 'b78b3e24-5b43-41fa-880d-d7cf008d0ec4'
}
}
const encoded = btoa(JSON.stringify(obj))
headers = {
'front-token': encoded,
'id-refresh-token': '218b03a5-71d3-40dd-b155-e35ae69eb7cd',
'Access-Control-Expose-Headers': 'id-refresh-token, front-token'
}
}
cy.intercept('POST', '/api/auth/session/refresh', {
statusCode,
headers
})
})
We're encoding the front-token with the payload and making sure to set the expiration to sometime in the future for the test.
This is the minimum I could set the headers to get a successful load of a page.
The command allows for adding custom status codes and headers for other test scenarios.csjaction
07/07/2022, 6:17 PMrp_st
07/07/2022, 6:47 PM