Skip to content

Commit

Permalink
Merge pull request #231 from sinamics/session_maxAge
Browse files Browse the repository at this point in the history
Define session maxAge using env variable
  • Loading branch information
sinamics committed Dec 9, 2023
2 parents f9426be + 4463260 commit a8ee2ca
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"quickfix.biome": true,
"source.organizeImports.biome": true
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
}
2 changes: 2 additions & 0 deletions docs/ztnet/docs/Installation/FreeBSD.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ setenv PRISMA_QUERY_ENGINE_LIBRARY /root/prisma-engines/target/release/libquery_
node .next/standalone/server.js
```
## Ztnet Environment Variables
See [Environment Variables](/installation/options#environment-variables) for more information.
18 changes: 1 addition & 17 deletions docs/ztnet/docs/Installation/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,4 @@ As an administrator, you possess unique capabilities not available to regular us
Please note that while admins have visibility over registered accounts, they **cannot** interact with or modify other users' networks directly. Each network's configuration and data remain exclusive to the respective user account, maintaining privacy and security for all users.

## Ztnet Environment Variables
The following environment variables are available for configuration. They can be set in the `.env` file or passed directly to the docker-compose.yml file.

```bash
ZT_ADDR # zerotier controller address. Defaults to `http://zerotier:9993` for docker environment, and `http://127.0.0.1:9993` for standalone.
ZT_SECRET #zerotier controller secret. Defaults to the content of `/var/lib/zerotier-one/authtoken.secret`.
NEXT_PUBLIC_SITE_NAME #Site name. Defaults to `ZTNET`.
POSTGRES_HOST #Default: postgres
POSTGRES_PORT #Default: 5432
POSTGRES_USER #Default: postgres
POSTGRES_PASSWORD #Default: postgres
POSTGRES_DB #Default: ztnet
NEXTAUTH_URL #Default: "http://localhost:3000" # Set the NEXTAUTH_URL environment variable to the canonical URL of your site.
NEXTAUTH_URL_INTERNAL # If provided, server-side calls will use this instead of NEXTAUTH_URL. Useful in environments when the server doesn't have access to the canonical URL of your site. Defaults to NEXTAUTH_URL.
NEXTAUTH_SECRET #Default: "random_secret", change this to a random string for security.
```

For more information on NEXTAUTH environment variables, see [NEXTAUTH Environment Variables](https://next-auth.js.org/configuration/options#environment-variables).
See [Environment Variables](/installation/options#environment-variables) for more information.
3 changes: 3 additions & 0 deletions docs/ztnet/docs/Installation/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ After following these steps, `ztnet` should be completely uninstalled from your
### Development

The installation scripts is available in the [install.ztnet](https://github.com/sinamics/ztnet/tree/main/install.ztnet) folder in main repository.

## Ztnet Environment Variables
See [Environment Variables](/installation/options#environment-variables) for more information.
83 changes: 83 additions & 0 deletions docs/ztnet/docs/Installation/options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
id: env-options
title: Environment Options
slug: /installation/options
description: Detailed documentation of environment variable options available for configuring the application.
---

# Application Configuration Options

This document outlines various environment variables and options that can be configured to customize the behavior of the application. Setting these variables correctly is crucial for the application to function as intended.

## Usage

### In Docker Compose

To use these environment variables in a Docker Compose setup, define them in your `docker-compose.yml` file under the `environment` section for the relevant service. For example:

```yaml
services:
ztnet:
environment:
ZT_ADDR: "`http://zerotier:9993`"
ZT_SECRET: "`your-zerotier-secret`"
NEXT_PUBLIC_SITE_NAME: "ZTNET"
# ... other environment variables ...
```

### In a Standalone Environment with .env File
```bash
ZT_ADDR="http://127.0.0.1:9993"
ZT_SECRET="your-zerotier-secret"
NEXT_PUBLIC_SITE_NAME="ZTNET"
```

## Available Environment options

Configure the application using the following environment variables:

- `ZT_ADDR`
- Description: ZeroTier controller address.
- Default: `http://zerotier:9993` for Docker environment, and `http://127.0.0.1:9993` for standalone.

- `ZT_SECRET`
- Description: ZeroTier controller secret.
- Default: Contents of `/var/lib/zerotier-one/authtoken.secret`.

- `NEXT_PUBLIC_SITE_NAME`
- Description: Site name.
- Default: `ZTNET`.

- `POSTGRES_HOST`
- Default: `postgres`.

- `POSTGRES_PORT`
- Default: `5432`.

- `POSTGRES_USER`
- Default: `postgres`.

- `POSTGRES_PASSWORD`
- Default: `postgres`.

- `POSTGRES_DB`
- Default: `ztnet`.

- `NEXTAUTH_URL`
- Description: Canonical URL of your site.
- Default: `http://localhost:3000`.

- `NEXTAUTH_URL_INTERNAL`
- Description: Server-side URL for NEXTAUTH. Used when the server doesn't have access to the canonical URL of your site.
- Default: Value of `NEXTAUTH_URL`.

- `NEXTAUTH_SECRET`
- Description: Secret key for NEXTAUTH, used for security.
- Default: `"random_secret"` (change to a random string for enhanced security).

- `NEXTAUTH_SESSION_MAX_AGE`
- Description: Duration (in seconds) before the user is logged out due to inactivity.
- Default: 2592000 (30 Days).


For more information on NEXTAUTH environment variables, see [NEXTAUTH Environment Variables](https://next-auth.js.org/configuration/options#environment-variables).
2 changes: 1 addition & 1 deletion src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const authOptions: NextAuthOptions = {
],
session: {
strategy: "jwt",
maxAge: 30 * 24 * 60 * 60, // 30 Days
maxAge: parseInt(process.env.NEXTAUTH_SESSION_MAX_AGE, 10) || 30 * 24 * 60 * 60, // 30 Days
},
callbacks: {
async jwt({ token, user, trigger, account, session }) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import { env } from "~/env.mjs";

// If it is not set, use the default value "ZTnet".
export const globalSiteTitle = "ZTNET";
export const globalSiteTitle = process.env.NEXT_PUBLIC_SITE_NAME || "ZTNET";

export const globalSiteVersion = env.NEXT_PUBLIC_APP_VERSION || null;

0 comments on commit a8ee2ca

Please sign in to comment.