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
This page is here to clarify how the pathing logic works in `@sidebase/nuxt-auth`.
4
+
You can find a full overview of how URLs are handled [in the issue comment](https://github.com/sidebase/nuxt-auth/pull/913#issuecomment-2359137989) and in spec files for [`authjs` provider](https://github.com/sidebase/nuxt-auth/blob/main/tests/authjs.url.spec.ts) and [`local` provider](https://github.com/sidebase/nuxt-auth/blob/main/tests/local.url.spec.ts).
5
+
6
+
## `baseURL` is a prefix
7
+
8
+
It will be prepended to a path before making a call. For example,
9
+
10
+
```ts
11
+
exportdefaultdefineNuxtConfig({
12
+
auth: {
13
+
baseURL: 'https://example.com/api/auth',
14
+
15
+
provider: {
16
+
type: 'local',
17
+
endpoints: {
18
+
// The call would be made to `https://example.com/api/auth/login`
19
+
signIn: { path: '/login', method: 'post' },
20
+
}
21
+
}
22
+
}
23
+
})
24
+
```
25
+
26
+
## Use URL provided in `endpoints` if it is fully specified
27
+
28
+
If you provide a full URL to `endpoints`, it will be used when making calls to an endpoint:
29
+
30
+
```ts {9}
31
+
exportdefaultdefineNuxtConfig({
32
+
auth: {
33
+
baseURL: 'https://your.website/api',
34
+
35
+
provider: {
36
+
type: 'local',
37
+
endpoints: {
38
+
// This will call `https://example.com/user`
39
+
getSession: { path: 'https://example.com/user' },
40
+
41
+
// This will call `https://your.website/api/login`
42
+
signIn: { path: '/login', method: 'post' },
43
+
},
44
+
}
45
+
}
46
+
})
47
+
```
48
+
49
+
## `runtimeConfig`
50
+
51
+
Value of `baseURL` is always located at `runtimeConfig.public.auth.baseURL`. You cannot change it directly as of the moment of writing, but you can read the value in your application:
52
+
53
+
```ts
54
+
const runtimeConfig =useRuntimeConfig()
55
+
const baseURL =runtimeConfig.public.auth.baseURL
56
+
```
57
+
58
+
This value is generally the [source of truth](https://github.com/sidebase/nuxt-auth/blob/b5af548c1fc390ae00496e19ad7a91d308af9b12/src/runtime/utils/url.ts#L37-L38). It is being [set in the plugin](https://github.com/sidebase/nuxt-auth/blob/b5af548c1fc390ae00496e19ad7a91d308af9b12/src/runtime/plugin.ts#L20-L24) to also be available on the client.
59
+
60
+
## Changing `baseURL`
61
+
62
+
Read next to understand how it can be changed.
63
+
64
+
### 1. Environment variables
65
+
66
+
You have multiple ways of changing the `baseURL` via env variables:
67
+
- use `NUXT_PUBLIC_AUTH_BASE_URL`;
68
+
- use `AUTH_ORIGIN` if `originEnvKey` is not set;
69
+
- use the environment variable name set in [`originEnvKey`](/guide/application-side/configuration#originenvkey)
70
+
71
+
Environment variables should work in both build-time and runtime.
72
+
73
+
### 2. `baseURL`
74
+
75
+
If you didn't set an environment variable, NuxtAuth will look for [`auth.baseURL`](/guide/application-side/configuration#baseurl) inside the `nuxt.config.ts`.
76
+
77
+
Note that this variable is always **static**, will only be set during runtime and can still be overriden in runtime using env variables.
78
+
79
+
Not setting `baseURL` will default to `/api/auth`.
80
+
81
+
### 3. `authjs` only: determine origin automatically from the incoming `HTTP` request
82
+
83
+
When the server is running in **development mode**, NuxtAuth can automatically infer `baseURL` from the incoming request.
84
+
85
+
---
86
+
87
+
Therefore as of version 0.10.0, we recommend the following setup to set your `AUTH_ORIGIN` or `baseURL`:
Copy file name to clipboardExpand all lines: docs/upgrade/version-0.10.0.md
+38-32Lines changed: 38 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,48 +43,33 @@ definePageMeta({
43
43
44
44
### Adjustments to the computation of `baseURL` and `AUTH_ORIGIN`
45
45
46
-
In 0.10.0 we spent a considerable amount of time reworking how `@sidebase/nuxt-auth`determine which endpoints to make requests to. If you would like to view the full PR and discussion, you can find it [here](https://github.com/sidebase/nuxt-auth/pull/913).
46
+
In 0.10.0 we spent a considerable amount of time reworking how `@sidebase/nuxt-auth`determines which endpoints to make requests to. If you would like to view the full PR and discussion, you can find it [here](https://github.com/sidebase/nuxt-auth/pull/913).
47
47
48
-
As a quick overview, `@sidebase/nuxt-auth` will now use the following logic to determine where to make requests to:
48
+
Read more [in a dedicated guide](../guide/advanced/url-resolutions.md).
49
49
50
-
#### 1. Environment variable and `runtimeConfig`
50
+
Below are some notable changes.
51
51
52
-
Use the `AUTH_ORIGIN` environment variable or `runtimeConfig.authOrigin` if set. Name can be customized, refer to [`originEnvKey`](/guide/application-side/configuration#originenvkey).
52
+
#### URLs are now joined
53
53
54
-
#### 2. `baseURL`
54
+
`baseURL` now means exactly that, it will be prepended to a path before making a call. That means you need to adjust your config accordingly:
55
55
56
-
Use the static [`baseURL`](/guide/application-side/configuration#baseurl) inside the `nuxt.config.ts` if set.
57
-
58
-
#### 3. Automatically from the incoming `HTTP` request
59
-
60
-
When the server is running in **development mode**, NuxtAuth can automatically infer it from the incoming request.
61
-
62
-
---
63
-
64
-
Therefore as of version 0.10.0, we recommend the following setup to set your `AUTH_ORIGIN` or `baseURL`:
### Adjustments when using an external backend for the `local`-provider
72
+
#### Adjustments when using an external backend for the `local`-provider
88
73
89
74
In previous versions of `@sidebase/nuxt-auth` a very specific setup was needed to ensure that external backends could properly be used for the `local` provider. In 0.10.0 we reworked the internal handling or URLs to make it more consistent across providers and configurations.
You can find a full overview of how `@sidebase/nuxt-auth` handles URLs [here](https://github.com/sidebase/nuxt-auth/pull/913#issuecomment-2359137989) and in spec files for [`authjs` provider](https://github.com/sidebase/nuxt-auth/blob/main/tests/authjs.url.spec.ts) and [`local` provider](https://github.com/sidebase/nuxt-auth/blob/main/tests/local.url.spec.ts).
94
+
---
95
+
96
+
Therefore as of version 0.10.0, we recommend the following setup to set your `AUTH_ORIGIN` or `baseURL`:
0 commit comments