You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/guides/authentication.mdx
+1-135Lines changed: 1 addition & 135 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,148 +11,14 @@ import ReadMore from '~/components/ReadMore.astro'
11
11
12
12
Authentication and authorization are two security processes that manage access to your website or app. Authentication verifies a visitor's identity, while authorization grants access to protected areas and resources.
13
13
14
-
Authentication allows you to customize areas of your site for logged-in individuals and provides the greatest protection for personal or private information. Authentication libraries (e.g. [Auth.js](https://authjs.dev/), [Clerk](https://clerk.com)) provide utilities for multiple authentication methods such as email sign-in and OAuth providers.
14
+
Authentication allows you to customize areas of your site for logged-in individuals and provides the greatest protection for personal or private information. Authentication libraries (e.g. [Better Auth](https://better-auth.com/), [Clerk](https://clerk.com)) provide utilities for multiple authentication methods such as email sign-in and OAuth providers.
15
15
16
16
:::tip
17
17
There is no official authentication solution for Astro, but you can find [community "auth" integrations](https://astro.build/integrations/?search=auth) in the integrations directory.
18
18
:::
19
19
20
20
<ReadMore>See how to [add authentication with Supabase](/en/guides/backend/supabase/#adding-authentication-with-supabase) or [add authentication with Firebase](/en/guides/backend/google-firebase/#adding-authentication-with-firebase) in our dedicated guides for these backend services.</ReadMore>
21
21
22
-
## Auth.js
23
-
24
-
Auth.js is a framework agnostic solution for authentication. A community framework adapter [`auth-astro`](https://www.npmjs.com/package/auth-astro) is available for Astro.
25
-
26
-
### Installation
27
-
28
-
Use the `astro add` command for your preferred package manager to add the `auth-astro` integration to an Astro project configured with a [server adapter](/en/guides/on-demand-rendering/#server-adapters) for on-demand rendering.
29
-
30
-
<PackageManagerTabs>
31
-
<Fragmentslot="npm">
32
-
```shell
33
-
npx astro add auth-astro
34
-
```
35
-
</Fragment>
36
-
<Fragmentslot="pnpm">
37
-
```shell
38
-
pnpm astro add auth-astro
39
-
```
40
-
</Fragment>
41
-
<Fragmentslot="yarn">
42
-
```shell
43
-
yarn astro add auth-astro
44
-
```
45
-
</Fragment>
46
-
</PackageManagerTabs>
47
-
48
-
#### Manual installation
49
-
50
-
To install `auth-astro` manually, install the required package for your package manager:
51
-
52
-
<PackageManagerTabs>
53
-
<Fragmentslot="npm">
54
-
```shell
55
-
npm install auth-astro @auth/core@^0.18.6
56
-
```
57
-
</Fragment>
58
-
<Fragmentslot="pnpm">
59
-
```shell
60
-
pnpm add auth-astro @auth/core@^0.18.6
61
-
```
62
-
</Fragment>
63
-
<Fragmentslot="yarn">
64
-
```shell
65
-
yarn add auth-astro @auth/core@^0.18.6
66
-
```
67
-
</Fragment>
68
-
</PackageManagerTabs>
69
-
70
-
Then, apply the integration to your `astro.config.*` file using the `integrations` property:
71
-
72
-
```ts title="astro.config.mjs" ins={3,8}
73
-
import { defineConfig } from'astro/config';
74
-
importnetlifyfrom'@astrojs/netlify';
75
-
importauthfrom'auth-astro';
76
-
77
-
exportdefaultdefineConfig({
78
-
// ...
79
-
adapter: netlify(),
80
-
integrations: [auth()],
81
-
});
82
-
```
83
-
84
-
### Configuration
85
-
86
-
Create an `auth.config.ts` file in your project's root directory. Add any auth [providers](https://authjs.dev/getting-started/providers) or methods you wish to support, along with any environment variables they require.
Create a `.env` file in the root of your project if it does not already exist. Add the following two environment variables. `AUTH_SECRET` should be a private string with a minimum of 32 characters.
103
-
104
-
```sh title=".env"
105
-
AUTH_TRUST_HOST=true
106
-
AUTH_SECRET=<my-auth-secret>
107
-
```
108
-
109
-
### Usage
110
-
111
-
You can add sign-in and sign-out buttons using the `auth-astro/client` module in a script tag or client-side framework component.
You can fetch the user's session using the `getSession` method.
130
-
131
-
```astro title="src/pages/index.astro" {3,7}
132
-
---
133
-
import Layout from 'src/layouts/Base.astro';
134
-
import { getSession } from 'auth-astro/server';
135
-
136
-
export const prerender = false; // Not needed in 'server' mode
137
-
138
-
const session = await getSession(Astro.request);
139
-
---
140
-
<Layout>
141
-
{
142
-
session ? (
143
-
<p>Welcome {session.user?.name}</p>
144
-
) : (
145
-
<p>Not logged in</p>
146
-
)
147
-
}
148
-
</Layout>
149
-
```
150
-
151
-
### Next Steps
152
-
153
-
-[`auth-astro` on GitHub](https://github.com/nowaythatworked/auth-astro?tab=readme-ov-file#auth-astro)
154
-
-[Auth.js documentation](https://authjs.dev/)
155
-
156
22
## Better Auth
157
23
158
24
Better Auth is a framework-agnostic authentication (and authorization) framework for TypeScript. It provides a comprehensive set of features out of the box and includes a plugin ecosystem that simplifies adding advanced functionalities.
0 commit comments