feat: Create admin account with environment variables, set secret, fix build issue
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
**/node_modules
|
||||
.svelte-kit
|
||||
build
|
||||
dist
|
||||
.idea
|
||||
.env
|
||||
.DS_Store
|
||||
|
||||
@@ -20,8 +20,6 @@ COPY . .
|
||||
|
||||
RUN npm run build
|
||||
|
||||
RUN npm run build --prefix backend
|
||||
|
||||
FROM --platform=linux/amd64 node:18-alpine as production
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
@@ -31,7 +29,6 @@ ENV NODE_ENV=production
|
||||
|
||||
COPY --from=pre-production /usr/src/app/backend/dist ./dist
|
||||
COPY --from=pre-production /usr/src/app/backend/node_modules ./node_modules
|
||||
COPY --from=pre-production /usr/src/app/dist ./dist/dist
|
||||
|
||||
COPY backend/package.json .
|
||||
COPY backend/package-lock.json .
|
||||
|
||||
@@ -61,6 +61,10 @@ services:
|
||||
container_name: reiverr
|
||||
ports:
|
||||
- 9494:9494
|
||||
environment:
|
||||
- SECRET=your_secret_here # optional, used to sign JWT tokens for authentication. If not set, sessions will not persist between server restarts. Use a random string.
|
||||
- ADMIN_USERNAME=admin # optional
|
||||
- ADMIN_PASSWORD=admin # optional
|
||||
volumes:
|
||||
- /path/to/appdata/config:/config
|
||||
restart: unless-stopped
|
||||
@@ -115,6 +119,8 @@ The roadmap includes plans to support the following platforms in the future:
|
||||
# Post Installation
|
||||
|
||||
To create the first user account, you can log in with any credentials and an admin account will be created.
|
||||
Alternatively, you can define the admin username and password using environment variables,
|
||||
as seen in the Docker Compose example. A new admin account is only created if there are no previous accounts with the same name.
|
||||
To get most out of Reiverr, it is recommended to connect to TMDB, Jellyfin, Radarr and Sonarr.
|
||||
|
||||
> Hint: Radarr & Sonarr API keys can be found under Settings > General in their respective web UIs. Jellyfin API key is located under Administration > Dashboard > Advanced > API Keys in the Jellyfin Web UI.
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
export const JWT_SECRET = Math.random().toString(36).substring(2, 15);
|
||||
export const JWT_SECRET =
|
||||
process.env.SECRET || Math.random().toString(36).substring(2, 15);
|
||||
export const ADMIN_USERNAME = process.env.ADMIN_USERNAME;
|
||||
export const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
|
||||
|
||||
@@ -3,8 +3,20 @@ import { AppModule } from './app.module';
|
||||
import 'reflect-metadata';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import * as fs from 'fs';
|
||||
import { UserService } from './user/user.service';
|
||||
import { ADMIN_PASSWORD, ADMIN_USERNAME } from './consts';
|
||||
// import * as proxy from 'express-http-proxy';
|
||||
|
||||
async function createAdminUser(userService: UserService) {
|
||||
if (!ADMIN_USERNAME || ADMIN_PASSWORD === undefined) return;
|
||||
|
||||
const existingUser = await userService.findOneByName(ADMIN_USERNAME);
|
||||
|
||||
if (!existingUser) {
|
||||
await userService.create(ADMIN_USERNAME, ADMIN_PASSWORD, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.setGlobalPrefix('api');
|
||||
@@ -20,6 +32,9 @@ async function bootstrap() {
|
||||
SwaggerModule.setup('openapi', app, document);
|
||||
fs.writeFileSync('./swagger-spec.json', JSON.stringify(document));
|
||||
|
||||
await createAdminUser(app.get(UserService));
|
||||
|
||||
await app.listen(9494);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user