Skip to content

Commit

Permalink
added self hosted deployment docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser committed Jul 4, 2024
1 parent 762d96d commit f55b842
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
47 changes: 45 additions & 2 deletions docs/guide/advanced/deployment/self-hosted.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# Coming soon
# Self Hosting

Oops, this page is not ready yet. You can find our current docs [here](https://sidebase.io).
This guide will explain how you can self-host a Nuxt3 application running NuxtAuth.

## Authjs Provider

When deploying the Auth.JS provider, the application must be informed what URL it is running at. This is to properly determine callback urls when navigating users to external OAuth providers. Depending on your setup, NuxtAuth allows you to set this value at either [**Runtime**](https://nuxt.com/docs/guide/going-further/hooks#app-hooks-runtime) or [**Buildtime**](https://nuxt.com/docs/guide/going-further/hooks#nuxt-hooks-build-time).

- **Runtime:** Set the `AUTH_ORIGIN` environment variable.
- **Buildtime:** Set the `baseURL`-config key inside the `nuxt.config.ts`

The origin consists out of:

- **scheme:** http / https
- **host:** e.g., localhost, example.org, google.com
- **port:** empty (implies `:80` for http and `:443` for https), :3000, :8888

An example of the `AUTH_ORIGIN` would be: `https://my-awsome-app.com`

:::info Origin Order
When [attempting to determine the server origin](https://github.com/sidebase/nuxt-auth/blob/main/src/runtime/server/services/utils.ts#L11), NuxtAuth checks the avalible options in the following order:
- **Prio 1**: Using `AUTH_ORIGIN`
- **Prio 2**: Using `baseURL`-config key from inside the `nuxt.config.ts`
- **Prio 3**: Infer the origin _(Only in development)_
:::

:::tip
We recommend setting the `AUTH_ORIGIN` during runtime and leaving the `baseURL`-config key empty, to avoid using a potentially incorrect ORIGIN.
:::

In addition to verifying that the origin is correctly set, also ensure that you have a secure [`secret` set in the NuxtAuthHandler](/guide/authjs/nuxt-auth-handler#secret).

## Local / Refresh Provider

When deploying a Local or Refresh -provider based app, you will only need to set the correct `baseURL` to your authentication backend.

This path can either be:

- **Reletive**: Pointing at a path inside your own application (e.g. `/api/auth`)
- **Absolute**: Pointing at a path inside an external application (e.g. `https://my-auth-backend/api`)

:::warning
For the `local` and `refresh` providers, this value will need to be set at build time. This is required to support static applications.

For this, ensure that you either directly set the `baseURL` inside the `nuxt.config.ts`, or provide a build-time environment variable that overwrites the value inside the `nuxt.config.ts`.
:::
2 changes: 1 addition & 1 deletion docs/guide/authjs/nuxt-auth-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineNuxtConfig({
})
```

```
``` txt [.env]
NUXT_AUTH_SECRET="YOUR-SUPER-SECURE-SECRET"
```

Expand Down

0 comments on commit f55b842

Please sign in to comment.