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

Reassinging body in requireAuth function fails with Netlify. #7

Open
LoyalEnv0y opened this issue Sep 7, 2023 · 2 comments
Open

Reassinging body in requireAuth function fails with Netlify. #7

LoyalEnv0y opened this issue Sep 7, 2023 · 2 comments

Comments

@LoyalEnv0y
Copy link

The workaround for redirect not having a body property works fine on local.

export async function requireAuth() {
	const isLoggedIn = false;

	if (!isLoggedIn) {
		const response = redirect('/login?message=You must be logged in');
		response.body = true; 
		throw response;
	}

	return null;
}

However reasigning the body is problametic because it throws this error

Cannot assign to 'body' because it is a read-only property.ts(2540)

It doesn't effect the local build but it fails on Netlify build step saying that

11:49:54 AM: Netlify Build                                                 
11:49:54 AM: ────────────────────────────────────────────────────────────────
11:49:54 AM: ​
11:49:54 AM: ❯ Version
11:49:54 AM:   @netlify/build 29.20.12
11:49:54 AM: ​
11:49:54 AM: ❯ Flags
11:49:54 AM:   baseRelDir: true
11:49:54 AM:   buildId: 64f98ea51381b90008fae837
11:49:54 AM:   deployId: 64f98ea51381b90008fae839
11:49:54 AM: ​
11:49:54 AM: ❯ Current directory
11:49:54 AM:   /opt/build/repo
11:49:54 AM: ​
11:49:54 AM: ❯ Config file
11:49:54 AM:   No config file was defined: using default values.
11:49:54 AM: ​
11:49:54 AM: ❯ Context
11:49:54 AM:   production
11:49:54 AM: ​
11:49:54 AM: Build command from Netlify app                                
11:49:54 AM: ────────────────────────────────────────────────────────────────
11:49:54 AM: ​
11:49:54 AM: $ npm run build
11:49:55 AM: > [email protected] build
11:49:55 AM: > tsc && vite build
11:49:56 AM: src/utils/index.ts(30,12): error TS2540: Cannot assign to 'body' because it is a read-only property.
11:49:57 AM: ​
11:49:57 AM: build.command failed                                        
11:49:57 AM: ────────────────────────────────────────────────────────────────
11:49:57 AM: ​
11:49:57 AM:   Error message
11:49:57 AM:   Command failed with exit code 2: npm run build (https://ntl.fyi/exit-code-2)
11:49:57 AM: ​
11:49:57 AM:   Error location
11:49:57 AM:   In Build command from Netlify app:
11:49:57 AM:   npm run build
11:49:57 AM: ​
11:49:57 AM:   Resolved config
11:49:57 AM:   build:
11:49:57 AM:     command: npm run build
11:49:57 AM:     commandOrigin: ui
11:49:57 AM:     publish: /opt/build/repo/dist
11:49:57 AM:     publishOrigin: ui
11:49:57 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:49:57 AM: Failing build: Failed to build site
11:49:58 AM: Finished processing build request in 15.608s

Is there a possible fix for this issue?

@CodeAnk2829
Copy link

Hey @LoyalEnv0y, I would like to work on this issue can you please assign me?

@LoyalEnv0y
Copy link
Author

Hey @CodeAnk2829 ! First of all thank you for responding to my thread. Sadly I am not a collaborator of this repository so I cannot make you an assignee. I believe you need to ask one of the collaborators of this repository for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants