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

Unclear Astro.redirect behavior in SSR #6644

Closed
1 task done
y-nk opened this issue Mar 24, 2023 · 1 comment · Fixed by #6719
Closed
1 task done

Unclear Astro.redirect behavior in SSR #6644

y-nk opened this issue Mar 24, 2023 · 1 comment · Fixed by #6719
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@y-nk
Copy link
Contributor

y-nk commented Mar 24, 2023

What version of astro are you using?

latest

Are you using an SSR adapter? If so, which one?

vercel@latest

What package manager are you using?

yarn

What operating system are you using?

doesn't matter

What browser are you using?

chromium

Describe the Bug

Usecase

I'm trying to create a "Protected Route" pattern where a page would be wrapped in a <ProtectedRoute> component which would redirect to /login if a user is not logged in.

Problem

  1. I've tried with a layout → there's an error
  2. I've tried with a component → there's an error
  3. I've tried with a separate page → it gets ignored

Question

Since we must return Astro.redirect(), it seems we can't wrap things up a level upper. How to proceed then?

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fnw2f4?file=src/pages/from-page.astro,src/pages/index.astro,src/pages/redirected.astro,src/pages/from-layout.astro,src/pages/from-component.astro,src/pages/from-other-page.astro&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp self-assigned this Mar 24, 2023
@matthewp matthewp added the - P3: minor bug An edge case that only affects very specific usage (priority) label Mar 24, 2023
@matthewp
Copy link
Contributor

This is the same issue as #6632. I'll try to create a better error message. But you can only use Astro.redirect, and set headers in the page component due to streaming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants