Redirecting inside a page in Fresh 2.0

Is returning a redirect response like this not working in Fresh 2.0 anymore?
import { define } from '../utils.ts';

export default define.page(function Page({ state }) {
if (!state.isLoggedIn) {
return new Response('', {
status: 307,
headers: { Location: '/sign-in' },
});
}

return (
<div style={{ display: 'flex' }}>
I am logged in
</div>
);
});
import { define } from '../utils.ts';

export default define.page(function Page({ state }) {
if (!state.isLoggedIn) {
return new Response('', {
status: 307,
headers: { Location: '/sign-in' },
});
}

return (
<div style={{ display: 'flex' }}>
I am logged in
</div>
);
});
Also, ctx.redirect is undefined so it's likely not implemented yet I believe?
2 Replies
marvinh.
marvinh.3w ago
1. Returning a Response instance is perfectly valid an should work. 2. ctx.redirect should work as well and isn't undefined. How are you accessing it?
TheSadMidDeveloper
This works
import { define } from '../utils.ts';

export const handlers = define.handlers({
GET(ctx) {
if (!ctx.state.auth.userId) {
return ctx.redirect('/sign-in')
}

return {
data: {}
}
}
})

export default define.page(function Page() {
return (
<div>
I am logged in
</div>
);
});
import { define } from '../utils.ts';

export const handlers = define.handlers({
GET(ctx) {
if (!ctx.state.auth.userId) {
return ctx.redirect('/sign-in')
}

return {
data: {}
}
}
})

export default define.page(function Page() {
return (
<div>
I am logged in
</div>
);
});
This (attached) doesnt. And ctx.redirect is undefined inside the define.page
No description