Welcome, {auth.session?.user?.name}!
Welcome, {session().user?.name}!
Welcome, {user.name}!
> ) : ( Sign in with GitHub )} ``` Note `data-astro-reload` keeps auth links and forms as full-page navigations when using Astro’s `ClientRouter`. The sign-out redirect must stay on the same origin. 6. ##### Protect a Page [Section titled “Protect a Page”](#protect-a-page) Check the session before rendering the page or loading private data. src/pages/account.astro ```astro --- export const prerender = false const { user } = await Astro.locals.getSession() if (!user) return Astro.redirect('/') ---Welcome, ${session.user.name}!
${auth.session.user?.name}
Welcome, {auth.session.user.name}!
{:else} {/if} ``` For protecting routes on the client side, you can use the `Welcome, {auth.session?.user?.name}!
Your code is ${code}. It expires in 10 minutes.
`, }), }) ``` The callback also receives `email`, `url`, `expiresAt` as a `Date`, and `purpose` (`'signin'` or `'link'`). `code` and `url` depend on the mode. Escape any user-provided values you include in HTML. ### Limits [Section titled “Limits”](#limits) `expiresIn` sets the lifetime in seconds, and `maxAttempts` sets how many code guesses a challenge allows. Their defaults are `600` and `5`. Sending limits use the verification store and are shared across server instances: ```ts Email({ from: 'login@example.com', send: Resend({ apiKey: env.RESEND_TOKEN }), rateLimit: { resendAfter: 60, perAddress: 5, perIp: 20, total: 100, getClientAddress: request => getTrustedClientAddress(request), }, }) ``` These are the defaults: a 60-second resend delay, 5 sends per address per hour, 20 per IP, and 100 total. Supply `getClientAddress` from your trusted server runtime to enable the IP limit. Gau does not trust forwarded headers automatically. Adjust the total for your app’s traffic. All limits must be positive integers. Email addresses are trimmed and lowercased. Gau does not remove dots or `+` tags. Codes and link tokens are stored as keyed hashes; do not log them in your sender or template callback. # Facebook > How to set up Facebook as an OAuth provider with gau. ### Resources [Section titled “Resources”](#resources) * [Arctic Facebook Provider](https://arcticjs.dev/providers/facebook) * [Meta for Developers - Apps](https://developers.facebook.com/apps) ### Environment variables [Section titled “Environment variables”](#environment-variables) .env ```txt FACEBOOK_CLIENT_ID= FACEBOOK_CLIENT_SECRET= ``` ### Callback URL [Section titled “Callback URL”](#callback-url) Add the callback URL in your Facebook App under “Facebook Login” → “Settings” → “Valid OAuth Redirect URIs”. Localhost URLs are automatically allowed. ```plaintext /api/auth/callback/facebook ``` ### Config [Section titled “Config”](#config) The `email` and `public_profile` scopes are requested by default. Note Make sure to enabled the `email` and `public_profile` permissions for your Facebook App! auth.ts ```ts import process from 'node:process' import { createAuth } from '@rttnd/gau/core' import { Facebook } from '@rttnd/gau/oauth' export const auth = createAuth({ providers: [ Facebook({ clientId: process.env.FACEBOOK_CLIENT_ID, clientSecret: process.env.FACEBOOK_CLIENT_SECRET, }), ], }) ``` ### Provider params [Section titled “Provider params”](#provider-params) #### params [Section titled “params”](#params) > Type: `RecordWelcome, {auth.session.user.name}!
{:else} {/if} ``` * Vanilla vite.config.ts ```ts import process from 'node:process' import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' const isTauri = !!process.env.TAURI_ENV_PLATFORM export default defineConfig({ plugins: [sveltekit()], server: { port: isTauri ? 4173 : 5173, strictPort: true, }, }) ``` * Solid 2 vite.config.ts ```ts import process from 'node:process' import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' const host = process.env.TAURI_DEV_HOST const isTauri = !!process.env.TAURI_ENV_PLATFORM const devPort = 1420 const hmrPort = 1430 export default defineConfig({ plugins: [sveltekit()], clearScreen: false, server: { port: isTauri ? devPort : 5173, strictPort: true, host: host || false, hmr: host ? { protocol: 'ws', host, port: hmrPort, } : undefined, }, }) ``` * Desktop The vanilla client ships with helpers tailored for Tauri. Listen for tokens delivered via the Tauri deep link bridge with `startTauriBridge`. src/main.ts ```diff import { createAuthClient } from '@rttnd/gau/client/vanilla' const authClient = createAuthClient({ baseUrl: import.meta.env.VITE_API_URL, scheme: 'gau', +}) +await authClient.startTauriBridge() +document.getElementById('sign-in-github')?.addEventListener('click', async () => { +await authClient.signIn('github') +}) +document.getElementById('sign-out')?.addEventListener('click', async () => { await authClient.signOut() }) ``` * Android Build the Tauri frontend without SSR or server functions. vite.config.ts ```ts import solid from '@solidjs/vite-plugin' import { defineConfig } from 'vite' export default defineConfig({ plugins: [solid({ start: true, ssr: false })], }) ``` Set `frontendDist` to `../dist/client` in `tauri.conf.json`. The Solid client handles the Tauri OAuth callback automatically. src/App.tsx ```tsx import { AuthProvider } from '@rttnd/gau/client/solid2'