Add local users
This commit is contained in:
@@ -2,7 +2,6 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Cron } from '@nestjs/schedule';
|
||||
import { MinioService } from 'src/minio/minio.service';
|
||||
require('dotenv').config();
|
||||
|
||||
// This should be a real class/interface representing a user entity
|
||||
export type User = {
|
||||
@@ -11,6 +10,15 @@ export type User = {
|
||||
password: string;
|
||||
};
|
||||
|
||||
const developmentUsers: User[] = [
|
||||
{
|
||||
userId: 1,
|
||||
username: 'admin',
|
||||
// "password"
|
||||
password: '$2b$10$c3d3JacaYw3KZ9qy4HniMeum5MXSj1VOOz8EWL5K23ZTL5aPnMNhS',
|
||||
}
|
||||
]
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
private users: User[] = [];
|
||||
@@ -28,6 +36,11 @@ export class UsersService {
|
||||
@Cron('* * * * *')
|
||||
async refreshUsers(): Promise<void> {
|
||||
this.logger.verbose('Refreshing users');
|
||||
if (this.configService.get<boolean>('isProduction', false) === false) {
|
||||
this.logger.verbose('Development environment, using development users');
|
||||
this.users = developmentUsers;
|
||||
return;
|
||||
}
|
||||
const buffer = await this.minioService.getBuffer(this.bucket, 'users.json');
|
||||
this.users = JSON.parse(buffer.toString());
|
||||
if (this.users === undefined) {
|
||||
|
Reference in New Issue
Block a user