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
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).
55
55
56
56
## `disableServerSideAuth`
57
57
@@ -63,33 +63,13 @@ Forces your server to send a "loading" authentication status on all requests, th
63
63
## `baseURL`
64
64
65
65
-**Type**: `string | undefined`
66
-
-**Default**:
67
-
- AuthJS Provider:
68
-
-_Development_: `http://localhost:3000/api/auth`
69
-
-_Production_: `undefined`
70
-
- Local / Refresh Provider: `/api/auth`
71
66
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.
73
68
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).
76
70
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:
-**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).
Copy file name to clipboardExpand all lines: docs/guide/local/quick-start.md
+5-45Lines changed: 5 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,6 @@
2
2
3
3
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`.
4
4
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
-
9
5
## Configuration
10
6
11
7
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.
14
10
exportdefaultdefineNuxtConfig({
15
11
modules: ['@sidebase/nuxt-auth'],
16
12
auth: {
17
-
baseURL: '/api/auth',
18
13
provider: {
19
14
type: 'local'
20
15
}
21
16
}
22
17
})
23
18
```
24
19
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
-
29
20
## API endpoints
30
21
31
22
Afterwards, you can define the endpoints to which the authentication requests will be made:
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.
52
46
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:
54
48
55
49
-**Sign in:**`/api/auth/login` (POST)
56
50
-**Sign out**`/api/auth/logout` (POST)
57
51
-**Sign up:**`/api/auth/register` (POST)
58
52
-**Get Session:**`/api/auth/session` (GET)
59
53
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
-
64
54
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.
You cannot disable the `getSession` endpoint, as NuxtAuth internally uses it to determine the authentication status.
82
71
:::
83
72
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
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
-
113
73
## Token
114
74
115
75
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