Skip to content

Commit 3fae562

Browse files
Remove Auth.js from authentication guide (withastro#12533)
Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent 04f99a2 commit 3fae562

File tree

1 file changed

+1
-135
lines changed

1 file changed

+1
-135
lines changed

src/content/docs/en/guides/authentication.mdx

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -11,148 +11,14 @@ import ReadMore from '~/components/ReadMore.astro'
1111

1212
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.
1313

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.
1515

1616
:::tip
1717
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.
1818
:::
1919

2020
<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>
2121

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-
<Fragment slot="npm">
32-
```shell
33-
npx astro add auth-astro
34-
```
35-
</Fragment>
36-
<Fragment slot="pnpm">
37-
```shell
38-
pnpm astro add auth-astro
39-
```
40-
</Fragment>
41-
<Fragment slot="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-
<Fragment slot="npm">
54-
```shell
55-
npm install auth-astro @auth/core@^0.18.6
56-
```
57-
</Fragment>
58-
<Fragment slot="pnpm">
59-
```shell
60-
pnpm add auth-astro @auth/core@^0.18.6
61-
```
62-
</Fragment>
63-
<Fragment slot="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-
import netlify from '@astrojs/netlify';
75-
import auth from 'auth-astro';
76-
77-
export default defineConfig({
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.
87-
88-
```ts title="auth.config.ts"
89-
import GitHub from '@auth/core/providers/github';
90-
import { defineConfig } from 'auth-astro';
91-
92-
export default defineConfig({
93-
providers: [
94-
GitHub({
95-
clientId: import.meta.env.GITHUB_CLIENT_ID,
96-
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET,
97-
}),
98-
],
99-
});
100-
```
101-
102-
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.
112-
113-
```astro title="src/pages/index.astro" {9}
114-
---
115-
import Layout from 'src/layouts/Base.astro';
116-
---
117-
<Layout>
118-
<button id="login">Login</button>
119-
<button id="logout">Logout</button>
120-
121-
<script>
122-
const { signIn, signOut } = await import("auth-astro/client")
123-
document.querySelector("#login").onclick = () => signIn("github")
124-
document.querySelector("#logout").onclick = () => signOut()
125-
</script>
126-
</Layout>
127-
```
128-
129-
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-
15622
## Better Auth
15723

15824
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

Comments
 (0)