mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
docs: update usage
This commit is contained in:
@@ -73,12 +73,13 @@ The `api` object exported from the auth instance contains all the actions that y
|
||||
"use server" // Waku currently only supports file-level "use server"
|
||||
|
||||
import { auth } from "./auth"
|
||||
import { unstable_getContext as getContext } from "waku/server"
|
||||
import { unstable_getHeaders as getHeaders } from "waku/server"
|
||||
|
||||
export const someAuthenticatedAction = async () => {
|
||||
"use server"
|
||||
const headers = getHeaders()
|
||||
const session = await auth.api.getSession({
|
||||
headers: new Headers(getContext().req.headers),
|
||||
headers,
|
||||
})
|
||||
};
|
||||
```
|
||||
@@ -88,20 +89,21 @@ export const someAuthenticatedAction = async () => {
|
||||
|
||||
```tsx
|
||||
import { auth } from "../auth"
|
||||
import { unstable_getContext as getContext } from "waku/server"
|
||||
import { unstable_getHeaders as getHeaders } from "waku/server"
|
||||
|
||||
export async function ServerComponent() {
|
||||
const session = await auth.api.getSession({
|
||||
headers: new Headers(getContext().req.headers),
|
||||
})
|
||||
if(!session) {
|
||||
return <div>Not authenticated</div>
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<h1>Welcome {session.user.name}</h1>
|
||||
</div>
|
||||
)
|
||||
const headers = getHeaders()
|
||||
const session = await auth.api.getSession({
|
||||
headers,
|
||||
})
|
||||
if(!session) {
|
||||
return <div>Not authenticated</div>
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<h1>Welcome {session.user.name}</h1>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user