mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 12:27:43 +00:00
Better Auth
This commit is contained in:
@@ -37,7 +37,7 @@ export default async function Home() {
|
|||||||
<div className="border-y py-2 border-dotted bg-secondary/60 opacity-80">
|
<div className="border-y py-2 border-dotted bg-secondary/60 opacity-80">
|
||||||
<div className="text-xs flex items-center gap-2 justify-center text-muted-foreground ">
|
<div className="text-xs flex items-center gap-2 justify-center text-muted-foreground ">
|
||||||
<span className="text-center">
|
<span className="text-center">
|
||||||
All features on this demo are Implemented with better auth
|
All features on this demo are implemented with Better Auth
|
||||||
without any custom backend code
|
without any custom backend code
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ Read the [Organization Plugin docs](/docs/plugins/organization#teams) for more i
|
|||||||
|
|
||||||
### **Init CLI**
|
### **Init CLI**
|
||||||
|
|
||||||
The CLI now includes an `init` command to add better auth to your project.
|
The CLI now includes an `init` command to add Better Auth to your project.
|
||||||
|
|
||||||
```bash title="terminal"
|
```bash title="terminal"
|
||||||
npx @better-auth/cli init
|
npx @better-auth/cli init
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title: API
|
|||||||
description: Better Auth API.
|
description: Better Auth API.
|
||||||
---
|
---
|
||||||
|
|
||||||
When you create a new Better Auth instance, it provides you with an `api` object. This object exposes every endpoint that exist in your better auth instance. And you can use this to interact with Better Auth server side.
|
When you create a new Better Auth instance, it provides you with an `api` object. This object exposes every endpoint that exist in your Better Auth instance. And you can use this to interact with Better Auth server side.
|
||||||
|
|
||||||
Any endpoint added to Better Auth, whether from plugins or the core, will be accessible through the `api` object.
|
Any endpoint added to Better Auth, whether from plugins or the core, will be accessible through the `api` object.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ description: Better Auth Hooks let you customize BetterAuth's behavior
|
|||||||
Hooks in Better Auth let you "hook into" the lifecycle and execute custom logic. They provide a way to customize Better Auth's behavior without writing a full plugin.
|
Hooks in Better Auth let you "hook into" the lifecycle and execute custom logic. They provide a way to customize Better Auth's behavior without writing a full plugin.
|
||||||
|
|
||||||
<Callout>
|
<Callout>
|
||||||
We highly recommend using hooks if you need to make custom adjustments to an endpoint rather than making another endpoint outside of better auth.
|
We highly recommend using hooks if you need to make custom adjustments to an endpoint rather than making another endpoint outside of Better Auth.
|
||||||
</Callout>
|
</Callout>
|
||||||
|
|
||||||
## Before Hooks
|
## Before Hooks
|
||||||
@@ -227,7 +227,7 @@ The password object provider `hash` and `verify`
|
|||||||
|
|
||||||
#### Adapter
|
#### Adapter
|
||||||
|
|
||||||
Adapter exposes the adapter methods used by better auth. Including `findOne`, `findMany`, `create`, `delete`, `update` and `updateMany`. You generally should use your actually `db` instance from your orm rather than this adapter.
|
Adapter exposes the adapter methods used by Better Auth. Including `findOne`, `findMany`, `create`, `delete`, `update` and `updateMany`. You generally should use your actually `db` instance from your orm rather than this adapter.
|
||||||
|
|
||||||
|
|
||||||
#### Internal Adapter
|
#### Internal Adapter
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ This tables will be created on the `public` schema.
|
|||||||
<Step>
|
<Step>
|
||||||
### Copy the migration script
|
### Copy the migration script
|
||||||
|
|
||||||
Now that we have the necessary tables in our database, we can run the migration script to migrate the users and accounts from supabase to better auth.
|
Now that we have the necessary tables in our database, we can run the migration script to migrate the users and accounts from supabase to Better Auth.
|
||||||
|
|
||||||
Start by creating a `.ts` file in your project.
|
Start by creating a `.ts` file in your project.
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ migrateFromSupabase();
|
|||||||
<Step>
|
<Step>
|
||||||
### Run the migration script
|
### Run the migration script
|
||||||
|
|
||||||
Run the migration script to migrate the users and accounts from supabase to better auth.
|
Run the migration script to migrate the users and accounts from supabase to Better Auth.
|
||||||
|
|
||||||
```bash title="Terminal"
|
```bash title="Terminal"
|
||||||
bun migration.ts # or use node, ts-node, etc.
|
bun migration.ts # or use node, ts-node, etc.
|
||||||
@@ -268,9 +268,9 @@ bun migration.ts # or use node, ts-node, etc.
|
|||||||
<Step>
|
<Step>
|
||||||
### Update your code
|
### Update your code
|
||||||
|
|
||||||
Update your codebase from supabase auth calls to better auth api.
|
Update your codebase from supabase auth calls to Better Auth api.
|
||||||
|
|
||||||
Here's a list of the supabase auth api calls and their better auth counterparts.
|
Here's a list of the supabase auth api calls and their Better Auth counterparts.
|
||||||
|
|
||||||
- `supabase.auth.signUp` -> `authClient.signUp.email`
|
- `supabase.auth.signUp` -> `authClient.signUp.email`
|
||||||
- `supabase.auth.signInWithPassword` -> `authClient.signIn.email`
|
- `supabase.auth.signInWithPassword` -> `authClient.signIn.email`
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ Expo is a popular framework for building cross-platform apps with React Native.
|
|||||||
<Step>
|
<Step>
|
||||||
## Configure Metro Bundler
|
## Configure Metro Bundler
|
||||||
|
|
||||||
To resolve better auth exports you'll need to enable `unstable_enablePackageExports` in your metro config.
|
To resolve Better Auth exports you'll need to enable `unstable_enablePackageExports` in your metro config.
|
||||||
|
|
||||||
```js title="metro.config.js"
|
```js title="metro.config.js"
|
||||||
const { getDefaultConfig } = require("expo/metro-config");
|
const { getDefaultConfig } = require("expo/metro-config");
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ Here's an example of how to use `getSession` in an Express route:
|
|||||||
|
|
||||||
```ts title="server.ts"
|
```ts title="server.ts"
|
||||||
import { fromNodeHeaders } from "better-auth/node";
|
import { fromNodeHeaders } from "better-auth/node";
|
||||||
import { auth } from "./auth"; //your better auth instance
|
import { auth } from "./auth"; // Your Better Auth instance
|
||||||
|
|
||||||
app.get("/api/me", async (req, res) => {
|
app.get("/api/me", async (req, res) => {
|
||||||
const session = await auth.api.getSession({
|
const session = await auth.api.getSession({
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ npx prisma db push
|
|||||||
|
|
||||||
Follow steps 1 & 2 from the [installation guide](/docs/installation) to install Better Auth in your Nitro application & set up the environment variables.
|
Follow steps 1 & 2 from the [installation guide](/docs/installation) to install Better Auth in your Nitro application & set up the environment variables.
|
||||||
|
|
||||||
Once that is done, create your better auth instance within the `server/utils/auth.ts` file.
|
Once that is done, create your Better Auth instance within the `server/utils/auth.ts` file.
|
||||||
|
|
||||||
```ts title="server/utils/auth.ts"
|
```ts title="server/utils/auth.ts"
|
||||||
import { betterAuth } from "better-auth";
|
import { betterAuth } from "better-auth";
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const { data: session } = await useSession(useFetch);
|
|||||||
<div class="border-y py-2 border-dotted bg-secondary/60 opacity-80">
|
<div class="border-y py-2 border-dotted bg-secondary/60 opacity-80">
|
||||||
<div class="text-xs flex items-center gap-2 justify-center text-muted-foreground">
|
<div class="text-xs flex items-center gap-2 justify-center text-muted-foreground">
|
||||||
<span class="text-center">
|
<span class="text-center">
|
||||||
All features on this demo are Implemented with better auth without
|
All features on this demo are Implemented with Better Auth without
|
||||||
any custom backend code
|
any custom backend code
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ $: to = $session.data ? "/dashboard" : "/sign-in";
|
|||||||
class="text-xs flex items-center gap-2 justify-center text-muted-foreground"
|
class="text-xs flex items-center gap-2 justify-center text-muted-foreground"
|
||||||
>
|
>
|
||||||
<span class="text-center">
|
<span class="text-center">
|
||||||
All features on this demo are Implemented with better auth without
|
All features on this demo are Implemented with Better Auth without
|
||||||
any custom backend code
|
any custom backend code
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export type BetterAuthOptions = {
|
|||||||
*/
|
*/
|
||||||
appName?: string;
|
appName?: string;
|
||||||
/**
|
/**
|
||||||
* Base URL for the better auth. This is typically the
|
* Base URL for the Better Auth. This is typically the
|
||||||
* root URL where your application server is hosted.
|
* root URL where your application server is hosted.
|
||||||
* If not explicitly set,
|
* If not explicitly set,
|
||||||
* the system will check the following environment variable:
|
* the system will check the following environment variable:
|
||||||
@@ -40,9 +40,9 @@ export type BetterAuthOptions = {
|
|||||||
*/
|
*/
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
/**
|
/**
|
||||||
* Base path for the better auth. This is typically
|
* Base path for the Better Auth. This is typically
|
||||||
* the path where the
|
* the path where the
|
||||||
* better auth routes are mounted.
|
* Better Auth routes are mounted.
|
||||||
*
|
*
|
||||||
* @default "/api/auth"
|
* @default "/api/auth"
|
||||||
*/
|
*/
|
||||||
@@ -51,7 +51,7 @@ export type BetterAuthOptions = {
|
|||||||
* The secret to use for encryption,
|
* The secret to use for encryption,
|
||||||
* signing and hashing.
|
* signing and hashing.
|
||||||
*
|
*
|
||||||
* By default better auth will look for
|
* By default Better Auth will look for
|
||||||
* the following environment variables:
|
* the following environment variables:
|
||||||
* process.env.BETTER_AUTH_SECRET,
|
* process.env.BETTER_AUTH_SECRET,
|
||||||
* process.env.AUTH_SECRET
|
* process.env.AUTH_SECRET
|
||||||
|
|||||||
Reference in New Issue
Block a user