├── dev.ts ├── deno.json ├── main.ts ├── README.md ├── components └── Button.tsx ├── routes ├── logout.ts ├── secret_or_redirect.tsx ├── secret_or_custom.tsx ├── api │ └── login.ts └── index.tsx ├── import_map.json └── fresh.gen.ts /dev.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S deno run -A --watch=static/,routes/ 2 | 3 | import dev from "$fresh/dev.ts"; 4 | 5 | await dev(import.meta.url, "./main.ts"); 6 | -------------------------------------------------------------------------------- /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "start": "deno run -A --watch=static/,routes/ dev.ts" 4 | }, 5 | "importMap": "./import_map.json", 6 | "compilerOptions": { 7 | "jsx": "react-jsx", 8 | "jsxImportSource": "preact" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | 7 | import { start } from "$fresh/server.ts"; 8 | import manifest from "./fresh.gen.ts"; 9 | 10 | await start(manifest); 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fresh Auth Example 2 | 3 | This is the example repo that accompanied the tutorial, 4 | [How to Setup Auth with Fresh](https://deno.com/blog/setup-auth-with-fresh). 5 | 6 | ## Usage 7 | 8 | Start the project: 9 | 10 | ``` 11 | deno task start 12 | ``` 13 | 14 | This will watch the project directory and restart as necessary. 15 | -------------------------------------------------------------------------------- /components/Button.tsx: -------------------------------------------------------------------------------- 1 | import { JSX } from "preact"; 2 | import { IS_BROWSER } from "$fresh/runtime.ts"; 3 | 4 | export function Button(props: JSX.HTMLAttributes) { 5 | return ( 6 | 28 | 29 | ); 30 | } 31 | 32 | export const handler: Handlers = { 33 | GET(req, ctx) { 34 | const cookies = getCookies(req.headers); 35 | 36 | return ctx.render!({ isAllowed: cookies.auth === "bar" }); 37 | }, 38 | }; 39 | --------------------------------------------------------------------------------