From e51a2b36eea8b8be50ff5b57c29dcd944d85b92f Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Sun, 13 Oct 2024 00:55:16 +0300 Subject: [PATCH] docs: fix minor details --- demo/nextjs/lib/auth.ts | 78 +++++++++++++++++++ docs/app/api/og/route.tsx | 45 +++-------- .../docs/concepts/session-management.mdx | 4 +- docs/content/docs/concepts/typescript.mdx | 4 +- docs/content/docs/integrations/svelte-kit.mdx | 21 ++--- .../src/api/routes/session.test.ts | 5 +- packages/better-auth/src/cli/get-config.ts | 1 + .../better-auth/src/db/internal-adapter.ts | 48 ++++++++---- packages/better-auth/src/utils/date.ts | 3 +- 9 files changed, 137 insertions(+), 72 deletions(-) diff --git a/demo/nextjs/lib/auth.ts b/demo/nextjs/lib/auth.ts index 8ed783ec..604ad7de 100644 --- a/demo/nextjs/lib/auth.ts +++ b/demo/nextjs/lib/auth.ts @@ -86,6 +86,82 @@ export const auth = betterAuth({ bearer(), admin(), ], + session: { + additionalFields: { + latitude: { + type: "string", + required: false, + }, + longitude: { + type: "string", + required: false, + }, + continent: { + type: "string", + required: false, + }, + country: { + type: "string", + required: false, + }, + region: { + type: "string", + required: false, + }, + city: { + type: "string", + required: false, + }, + timezone: { + type: "string", + required: false, + }, + browserName: { + type: "string", + required: false, + }, + browserVersion: { + type: "string", + required: false, + }, + browserMajor: { + type: "string", + required: false, + }, + engineName: { + type: "string", + required: false, + }, + engineVersion: { + type: "string", + required: false, + }, + osName: { + type: "string", + required: false, + }, + osVersion: { + type: "string", + required: false, + }, + deviceVendor: { + type: "string", + required: false, + }, + deviceModel: { + type: "string", + required: false, + }, + deviceType: { + type: "string", + required: false, + }, + cpuArchitecture: { + type: "string", + required: false, + }, + }, + }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID || "", @@ -105,3 +181,5 @@ export const auth = betterAuth({ }, }, }); + +type A = typeof auth.$Infer.Session; diff --git a/docs/app/api/og/route.tsx b/docs/app/api/og/route.tsx index 0971aaf5..84b40797 100644 --- a/docs/app/api/og/route.tsx +++ b/docs/app/api/og/route.tsx @@ -118,8 +118,7 @@ export async function GET(req: Request) { // this is used with the above example // const validParams = ogSchema.parse(ogData); const validParams = ogSchema.parse(urlParamsValues); - console.log({ urlParamsValues }); - console.log("THE VALUD PARAMS: ", { validParams }); + const { heading, type, mode } = validParams; const trueHeading = heading.length > 140 ? `${heading.substring(0, 140)}...` : heading; @@ -214,44 +213,18 @@ export async function GET(req: Request) { /> - - - - -
diff --git a/docs/content/docs/concepts/session-management.mdx b/docs/content/docs/concepts/session-management.mdx index b49da8dc..05e5230f 100644 --- a/docs/content/docs/concepts/session-management.mdx +++ b/docs/content/docs/concepts/session-management.mdx @@ -27,8 +27,8 @@ import { betterAuth } from "better-auth" export const auth = betterAuth({ //... other config options session: { - expiresIn: 1000 * 60 * 60 * 24 * 7 // 7 days, - updateAge: 1000 * 60 * 60 * 24 // 1 day (every 1 day the session expiration is updated) + expiresIn: 60 * 60 * 24 * 7 // 7 days, + updateAge: 60 * 60 * 24 // 1 day (every 1 day the session expiration is updated) } }) ``` diff --git a/docs/content/docs/concepts/typescript.mdx b/docs/content/docs/concepts/typescript.mdx index 623b9021..3f9779b2 100644 --- a/docs/content/docs/concepts/typescript.mdx +++ b/docs/content/docs/concepts/typescript.mdx @@ -84,7 +84,9 @@ import { inferAdditionalFields } from "better-auth/client/plugins"; export const authClient = createAuthClient({ plugins: [inferAdditionalFields({ user: { - role: "string" + role: { + type: "string" + } } })], }); diff --git a/docs/content/docs/integrations/svelte-kit.mdx b/docs/content/docs/integrations/svelte-kit.mdx index 8e77cd69..d51834bd 100644 --- a/docs/content/docs/integrations/svelte-kit.mdx +++ b/docs/content/docs/integrations/svelte-kit.mdx @@ -2,6 +2,7 @@ title: Svelte Kit Integration description: Learn how to integrate Better Auth with Svelte Kit --- + Before you start, make sure you have a Better Auth instance configured. If you haven't done that yet, check out the [installation](/docs/installation). ### Mount the handler @@ -17,14 +18,6 @@ export async function handle({ event, resolve }) { } ``` -### Migrate the database -Run the following command to create the necessary tables in your database: - -```bash -npx better-auth migrate -``` - - ## Create a client Create a client instance. You can name the file anything you want. Here we are creating `client.ts` file inside the `lib/` directory. @@ -32,7 +25,7 @@ Create a client instance. You can name the file anything you want. Here we are c ```ts title="client.ts" import { createAuthClient } from "better-auth/svelte" // make sure to import from better-auth/svelte -export const client = createAuthClient({ +export const authClient = createAuthClient({ //you can pass client configuration here }) ``` @@ -43,18 +36,18 @@ Some of the actions are reactive. The client use [nano-store](https://github.com ### Example usage ```svelte
- {#if $session} + {#if $session.data}

{$session?.data?.user.name}