Error when using Cypress to login with Azure Active Directory #6888
Replies: 1 comment 10 replies
-
Not sure if there's a better way yet, but Cypress and Next-auth directly contradict eachother. Cypress says never to login via redirects, next-auth has an example encouraging that. I ran in to a similar issue as you, after allowing Cypress to go through the redirect flow. I think the issue was somehow related to cypress setting cookies differently than when the app is running in a browser normally (this is likely where your issue comes from). Cypress recommends mocking/programmatically setting the logged in state to your application. I ended up creating a cypress login command that borrowed some code from next-auth's source code to create and store the next auth session cookie. It works, but it's not ideal. I would not use Next Auth in a future project in part due to this reason. |
Beta Was this translation helpful? Give feedback.
-
I followed this tutorial to login via Azure Active Directory using Cypress.
The login works, up until the last point when the following error occurs:
I am using the middleware to protect all my pages and when this error occurs the user is rerouted to the login page.
I am not sure how I am supposed to fix this or if there is an example somewhere with Azure AD + Cypress + Next-Auth.
Any help with how to fix this or an example would help a lot.
Beta Was this translation helpful? Give feedback.
All reactions