This commit is contained in:
parent
7e2df59a9b
commit
bc010c94ff
@ -129,7 +129,7 @@ export class AuthService {
|
|||||||
secure: isProduction || cookieSecure,
|
secure: isProduction || cookieSecure,
|
||||||
sameSite: "none" as const,
|
sameSite: "none" as const,
|
||||||
path: isRefreshToken ? "/auth/refresh" : "/",
|
path: isRefreshToken ? "/auth/refresh" : "/",
|
||||||
domain: domain?.startsWith(".") ? domain : `.${domain}`,
|
domain: domain,
|
||||||
maxAge: isRefreshToken ? 7 * 24 * 60 * 60 * 1000 : 15 * 60 * 1000,
|
maxAge: isRefreshToken ? 7 * 24 * 60 * 60 * 1000 : 15 * 60 * 1000,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
import { Injectable, OnModuleInit } from "@nestjs/common";
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from "@nestjs/typeorm";
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from "typeorm";
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from "@nestjs/config";
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from "bcrypt";
|
||||||
import { User } from './entities';
|
import { User } from "./entities";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService implements OnModuleInit {
|
export class UsersService implements OnModuleInit {
|
||||||
@ -18,14 +18,14 @@ export class UsersService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async seedAdminUser() {
|
private async seedAdminUser() {
|
||||||
const adminUsername = this.configService.get<string>('ADMIN_USERNAME') || 'admin';
|
const adminUsername =
|
||||||
|
this.configService.get<string>("ADMIN_USERNAME") || "admin";
|
||||||
|
|
||||||
const existingAdmin = await this.usersRepository.findOne({
|
const existingAdmin = await this.usersRepository.findOne({
|
||||||
where: { username: adminUsername },
|
where: { username: adminUsername },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existingAdmin) {
|
if (!existingAdmin) {
|
||||||
// Create admin without password - requires setup on first login
|
|
||||||
const admin = this.usersRepository.create({
|
const admin = this.usersRepository.create({
|
||||||
username: adminUsername,
|
username: adminUsername,
|
||||||
password: null,
|
password: null,
|
||||||
@ -33,7 +33,9 @@ export class UsersService implements OnModuleInit {
|
|||||||
isPasswordSet: false,
|
isPasswordSet: false,
|
||||||
});
|
});
|
||||||
await this.usersRepository.save(admin);
|
await this.usersRepository.save(admin);
|
||||||
console.log(`Admin user "${adminUsername}" created - password setup required`);
|
console.log(
|
||||||
|
`Admin user "${adminUsername}" created - password setup required`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +65,7 @@ export class UsersService implements OnModuleInit {
|
|||||||
async setupPassword(username: string, password: string): Promise<User> {
|
async setupPassword(username: string, password: string): Promise<User> {
|
||||||
const user = await this.findByUsername(username);
|
const user = await this.findByUsername(username);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error('User not found');
|
throw new Error("User not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const hashedPassword = await bcrypt.hash(password, 10);
|
const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user