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