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
ctx.render
undefined
Fresh version 1.6.8 Deno version 1.43.5
Hello, I tried to do the same thing as in this blog https://deno.com/blog/setup-auth-with-fresh
import type { Handlers, PageProps } from "$fresh/server.ts"; import { getCookies } from "std/http/cookie.ts"; interface Data { isAllowed: boolean; } export const handler: Handlers = { GET(req, ctx) { const cookies = getCookies(req.headers); return ctx.render!({ isAllowed: cookies.auth === "bar" }); }, }; export default function Home({ data }: PageProps<Data>) { return ( <div> <div> You currently {data.isAllowed ? "are" : "are not"} logged in. </div> </div> ); }
And my code looks like this
interface AuthData { isAllowed: boolean; } export const handler: Handlers = { GET(req, ctx) { const cookies = getCookies(req.headers); return ctx.render({ isAllowed: cookies.auth === "bar" } satisfies AuthData); }, }; export default async function Home(props: PageProps<AuthData>) { console.log(props.data); ... }
And in the result I see that props.data is undefined
props.data
But if I'll remove async from the Home like this:
async
Home
interface AuthData { isAllowed: boolean; } export const handler: Handlers = { GET(req, ctx) { const cookies = getCookies(req.headers); return ctx.render({ isAllowed: cookies.auth === "bar" } satisfies AuthData); }, }; export default function Home(props: PageProps<AuthData>) { console.log(props.data); ... }
then I can see { isAllowed: false } as expected
{ isAllowed: false }
The text was updated successfully, but these errors were encountered:
Whoops, my bad Found in the documentation https://fresh.deno.dev/docs/concepts/routes that route parameters should be rewritten to
export default async function Home(req: Request, ctx: RouteContext) { console.log(ctx.data); }
Fresh version 1.6.8
Deno version 1.43.5
Hello, I tried to do the same thing as in this blog https://deno.com/blog/setup-auth-with-fresh
And my code looks like this
And in the result I see that
props.data
isundefined
But if I'll remove
async
from theHome
like this:then I can see
{ isAllowed: false }
as expectedThe text was updated successfully, but these errors were encountered: