Skip to content

Commit 03daf87

Browse files
committed
Adjusted docs to match new origin env system
1 parent 985c497 commit 03daf87

File tree

3 files changed

+15
-71
lines changed

3 files changed

+15
-71
lines changed

docs/.vitepress/routes/navbar.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ export const routes: DefaultTheme.Config['nav'] = [
4444
],
4545
},
4646
{
47-
text: '0.9.4',
47+
text: '0.10.0',
4848
items: [
49+
{
50+
text: '0.9.4',
51+
link: 'https://github.com/sidebase/nuxt-auth/tree/0.9.4/docs',
52+
},
4953
{
5054
text: '0.8.2',
5155
link: 'https://github.com/sidebase/nuxt-auth/tree/0.8.2/docs',

docs/guide/application-side/configuration.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default defineNuxtConfig({
5151
```
5252
:::
5353

54-
You can read additional information on `origin` determining [here](/resources/error-reference#auth-no-origin).
54+
You can read additional information on `origin` and `baseURL` determining [here](/resources/error-reference#auth-no-origin).
5555

5656
## `disableServerSideAuth`
5757

@@ -63,33 +63,13 @@ Forces your server to send a "loading" authentication status on all requests, th
6363
## `baseURL`
6464

6565
- **Type**: `string | undefined`
66-
- **Default**:
67-
- AuthJS Provider:
68-
- _Development_: `http://localhost:3000/api/auth`
69-
- _Production_: `undefined`
70-
- Local / Refresh Provider: `/api/auth`
7166

72-
The full url at which the app will run combined with the path to authentication. You can set this differently depending on your selected authentication-provider:
67+
The full url at which the app will run combined with the path to authentication. You should only use `baseURL` if you want to staticlly set a baseURL for your application.
7368

74-
- `authjs`: You must set the full URL, with origin and path in production. You can leave this empty in development
75-
- `local`: You can set a full URL, but can also leave this empty to fallback to the default value of `/api/auth` or set only the path.
69+
You can read additional information on `origin` and `baseURL` determining [here](/resources/error-reference#auth-no-origin).
7670

77-
### `authjs` Provider
78-
79-
`baseURL` can be `undefined` during development but _must_ be set to the combination of origin + path that points to your `NuxtAuthHandler` for production. The origin consists out of:
80-
- **scheme**: http / https
81-
- **host**: e.g., localhost, example.org, google.com
82-
- **port**: _empty_ (implies `:80` for http and `:443` for https), :3000, :8888
83-
- **path**: the path that directs to the location of your `NuxtAuthHandler` e.g. `/api/auth`
84-
85-
### `local` Provider
86-
87-
Defaults to `/api/auth` for both development and production. Setting this is optional, if you set it you can set it to either:
88-
- just a path: Will lead to `nuxt-auth` using `baseURL` as a relative path appended to the origin you deploy to. Example: `/backend/auth`
89-
- an origin and a path: Will lead to `nuxt-auth` using `baseURL` as an absolute request path to perform requests to. Example: `https://example.com/auth`
90-
91-
:::warning
92-
If you point to a different origin than the one you deploy to you likely have to take care of CORS: Allowing cross origin requests.
71+
::: tip
72+
If you would like to overwrite the `baseURL` at the runtime you can use the [`originEnvKey`](#originenvkey).
9373
:::
9474

9575
## `provider`

docs/guide/local/quick-start.md

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
This guide is for setting up `@sidebase/nuxt-auth` with the Local Provider, which is best suited for when you already have a backend that accepts username + password as a login or want to build a static application. The Local Provider also supports refresh tokens since `v0.9.0`.
44

5-
:::warning Breaking change
6-
In `v0.9.0` the `refresh` provider was integrated into the `local` provider. Read the [upgrade guide](/upgrade/version-0.9.0).
7-
:::
8-
95
## Configuration
106

117
The entire configuration for the `local` provider is contained inside the `nuxt.config.ts`. Inside the `auth` options, set your provider to `local`.
@@ -14,27 +10,25 @@ The entire configuration for the `local` provider is contained inside the `nuxt.
1410
export default defineNuxtConfig({
1511
modules: ['@sidebase/nuxt-auth'],
1612
auth: {
17-
baseURL: '/api/auth',
1813
provider: {
1914
type: 'local'
2015
}
2116
}
2217
})
2318
```
2419

25-
:::tip
26-
Ensure that your `baseURL` is properly configured to match your backend API. Read more [here](/guide/application-side/configuration#local-and-refresh).
27-
:::
28-
2920
## API endpoints
3021

3122
Afterwards, you can define the endpoints to which the authentication requests will be made:
3223

3324
```ts
3425
export default defineNuxtConfig({
3526
// ...Previous configuration
27+
runtimeConfig: {
28+
baseURL: '/api/auth'
29+
},
3630
auth: {
37-
baseURL: '/api/auth',
31+
originEnvKey: 'NUXT_BASE_URL',
3832
provider: {
3933
type: 'local',
4034
endpoints: {
@@ -50,23 +44,18 @@ export default defineNuxtConfig({
5044

5145
Each endpoint, consists of an object, with a `path` and `method`. When a user triggers an action inside your application a request will be made to each endpoint. When a request is made to the `getSession` endpoint, a token will be sent as a header. You can configure the headers and token below.
5246

53-
In the example above requests would be made to the following URLs:
47+
In the example above, we define a runtimeConfig value with the `baseURl` using the originEnvKey, which results in requests being made to the following urls:
5448

5549
- **Sign in:** `/api/auth/login` (POST)
5650
- **Sign out** `/api/auth/logout` (POST)
5751
- **Sign up:** `/api/auth/register` (POST)
5852
- **Get Session:** `/api/auth/session` (GET)
5953

60-
:::info
61-
Relative paths starting with a `/` (e.g. `/login`) will be treated as a part of your Nuxt application. If you want to use an external backend, please provide fully-specified URLs instead. Read more [here](#using-an-external-backend).
62-
:::
63-
6454
You can customize each endpoint to fit your needs or disable it by setting it to `false`. For example you may want to disable the `signUp` endpoint.
6555

6656
```ts{7}
6757
export default defineNuxtConfig({
6858
auth: {
69-
baseURL: '/api/auth',
7059
provider: {
7160
type: 'local',
7261
endpoints: {
@@ -81,35 +70,6 @@ export default defineNuxtConfig({
8170
You cannot disable the `getSession` endpoint, as NuxtAuth internally uses it to determine the authentication status.
8271
:::
8372

84-
### Using an external backend
85-
86-
When using the `local` provider to access an external backend, please consider that the module will attempt to resolve the API endpoints by using internal Nuxt 3 relative URLs or an external call.
87-
88-
To ensure that the module can properly identify that your endpoints point to an external URL, please ensure the following:
89-
90-
1. `auth.baseURL` **includes** a trailing `/` at the end
91-
2. `auth.endpoints` **do not** include a leading `/` at the start
92-
93-
```ts{7}
94-
export default defineNuxtConfig({
95-
auth: {
96-
baseURL: 'https://external-api.com', // [!code --]
97-
baseURL: 'https://external-api.com/', // [!code ++]
98-
provider: {
99-
type: 'local',
100-
endpoints: {
101-
signIn: { path: '/login', method: 'post' }, // [!code --]
102-
signIn: { path: 'login', method: 'post' }, // [!code ++]
103-
getSession: { path: '/session', method: 'get' }, // [!code --]
104-
getSession: { path: 'session', method: 'get' }, // [!code ++]
105-
}
106-
}
107-
}
108-
})
109-
```
110-
111-
You can read more about the path resolving logic in `@sidebase/nuxt-auth` [here](https://github.com/sidebase/nuxt-auth/issues/782#issuecomment-2223861422).
112-
11373
## Token
11474

11575
The `local` and `refresh` providers are both based on exchanging access tokens with your backend. NuxtAuth expects an access token to be provided by the `signIn` endpoint, which will then be saved into the session to authenticate further requests to e.g. `getSession`.

0 commit comments

Comments
 (0)