-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add temp auth config as a playwright workaround
- Loading branch information
1 parent
8cb79db
commit 7aadaba
Showing
4 changed files
with
49 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file is a workaround to populate state.login.authDetails | ||
// the auth is overridden when testing due to DEBUG=True on the backend, | ||
// but we need to update the frontend state to show we are logged in | ||
|
||
import axios from 'axios'; | ||
import { getUserDetailsFromApi } from '@/utilfunctions/login'; | ||
import { CommonActions } from '@/store/slices/CommonSlice'; | ||
import CoreModules from '@/shared/CoreModules.js'; | ||
import { LoginActions } from '@/store/slices/LoginSlice'; | ||
|
||
async function PlaywrightTempAuth() { | ||
const dispatch = CoreModules.useAppDispatch(); | ||
// Sets a cookie in the browser that is used for auth | ||
await axios.get(`${import.meta.env.VITE_API_URL}/auth/temp-login`); | ||
|
||
const apiUser = await getUserDetailsFromApi(); | ||
if (!apiUser) { | ||
dispatch( | ||
CommonActions.SetSnackBar({ | ||
open: true, | ||
message: 'Temp login failed. Try OSM.', | ||
variant: 'error', | ||
duration: 2000, | ||
}), | ||
); | ||
return; | ||
} | ||
|
||
dispatch(LoginActions.setAuthDetails(apiUser)); | ||
} | ||
|
||
export default PlaywrightTempAuth; |