Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky auth test with console error "Failed to fetch" #3287

Merged
merged 16 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"format-util": "1.0.5",
"globby": "14.0.1",
"jsdom": "24.0.0",
"lerna": "8.1.2",
"lerna": "7.4.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lerna 7 until this gets fixed: lerna/lerna#3964

"markdownlint-cli2": "0.12.1",
"prettier": "3.2.5",
"pretty-quick": "4.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/create-toolpad-app/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ async function waitForMatch(input: Readable, regex: RegExp): Promise<RegExpExecA
});
}

// @TODO: Unskip once @toolpad/studio is released for the first time.
test.skip(
test(
'create-toolpad-app can bootstrap a Toolpad Studio app',
async () => {
testDir = await fs.mkdtemp(path.resolve(os.tmpdir(), './test-app-'));
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-studio/src/runtime/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function SignInPage() {
React.useEffect(() => {
const authError = urlParams.get(AUTH_ERROR_URL_PARAM);

if (authError === 'AuthorizedCallbackError') {
if (authError === 'AuthorizedCallbackError' || authError === 'CredentialsSignin') {
setErrorSnackbarMessage('Access unauthorized.');
} else if (authError === 'CallbackRouteError') {
setErrorSnackbarMessage(
Expand Down
9 changes: 8 additions & 1 deletion packages/toolpad-studio/src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,16 @@ export async function createRequireAuthMiddleware(project: ToolpadProject) {

const isPageRequest = req.get('sec-fetch-dest') === 'document';
const signInPath = `${base}/signin`;
const editorPath = `${base}/editor`;

const requestPath = req.originalUrl.split('?')[0];

let isAuthorized = true;
if ((!project.options.dev || isPageRequest) && req.originalUrl.split('?')[0] !== signInPath) {
if (
(!project.options.dev || isPageRequest) &&
!requestPath.startsWith(signInPath) &&
!requestPath.startsWith(editorPath)
) {
const token = await getUserToken(req);
if (!token) {
isAuthorized = false;
Expand Down
Loading
Loading