refactor: 调整userSession服务及实体至Auth模块下
This commit is contained in:
@@ -8,6 +8,7 @@ import { AdminWebResourceController } from './controller/web/admin-web-resource.
|
|||||||
import { AdminWebBlogController } from './controller/web/admin-web-blog.controller';
|
import { AdminWebBlogController } from './controller/web/admin-web-blog.controller';
|
||||||
import { ResourceModule } from 'src/resource/resource.module';
|
import { ResourceModule } from 'src/resource/resource.module';
|
||||||
import { BlogModule } from 'src/blog/blog.module';
|
import { BlogModule } from 'src/blog/blog.module';
|
||||||
|
import { AuthModule } from 'src/auth/auth.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -15,6 +16,7 @@ import { BlogModule } from 'src/blog/blog.module';
|
|||||||
UserModule,
|
UserModule,
|
||||||
ResourceModule,
|
ResourceModule,
|
||||||
BlogModule,
|
BlogModule,
|
||||||
|
AuthModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
AdminController,
|
AdminController,
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { LoginByPasswordDto } from './dto/login.dto';
|
import { LoginByPasswordDto } from './dto/login.dto';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { UserSessionService } from 'src/user/services/user-session.service';
|
import { UserSessionService } from 'src/auth/service/user-session.service';
|
||||||
import { Throttle, ThrottlerGuard } from '@nestjs/throttler';
|
import { Throttle, ThrottlerGuard } from '@nestjs/throttler';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { UserService } from 'src/user/user.service';
|
import { UserService } from 'src/user/user.service';
|
||||||
import { AuthGuard } from './guards/auth.guard';
|
import { AuthGuard } from './guards/auth.guard';
|
||||||
import { SmsLoginDto } from './dto/sms-login.dto';
|
import { SmsLoginDto } from './dto/sms-login.dto';
|
||||||
import { SmsService } from 'src/sms/sms.service';
|
import { SmsService } from 'src/sms/sms.service';
|
||||||
import { UserSession } from 'src/user/entities/user-session.entity';
|
import { UserSession } from 'src/auth/entity/user-session.entity';
|
||||||
|
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
|
|||||||
@@ -3,23 +3,25 @@ import { AuthController } from './auth.controller';
|
|||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { UserModule } from 'src/user/user.module';
|
import { UserModule } from 'src/user/user.module';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { UserSession } from 'src/user/entities/user-session.entity';
|
import { UserSession } from 'src/auth/entity/user-session.entity';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { VerificationModule } from 'src/verification/verification.module';
|
import { VerificationModule } from 'src/verification/verification.module';
|
||||||
import { AuthGuard } from './guards/auth.guard';
|
import { AuthGuard } from './guards/auth.guard';
|
||||||
import { OptionalAuthGuard } from './guards/optional-auth.guard';
|
import { OptionalAuthGuard } from './guards/optional-auth.guard';
|
||||||
import { SmsModule } from 'src/sms/sms.module';
|
import { SmsModule } from 'src/sms/sms.module';
|
||||||
|
import { PasskeyCredential } from './entity/passkey-credential.entity';
|
||||||
|
import { UserSessionService } from './service/user-session.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
forwardRef(() => UserModule),
|
forwardRef(() => UserModule),
|
||||||
TypeOrmModule.forFeature([UserSession]),
|
TypeOrmModule.forFeature([UserSession, PasskeyCredential]),
|
||||||
VerificationModule,
|
VerificationModule,
|
||||||
SmsModule,
|
SmsModule,
|
||||||
],
|
],
|
||||||
controllers: [AuthController],
|
controllers: [AuthController],
|
||||||
providers: [AuthService, AuthGuard, OptionalAuthGuard],
|
providers: [AuthService, AuthGuard, OptionalAuthGuard, UserSessionService],
|
||||||
exports: [AuthService, AuthGuard, OptionalAuthGuard],
|
exports: [AuthService, AuthGuard, OptionalAuthGuard, UserSessionService],
|
||||||
})
|
})
|
||||||
export class AuthModule { }
|
export class AuthModule { }
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import { UserService } from 'src/user/user.service';
|
import { UserService } from 'src/user/user.service';
|
||||||
import { UserSessionService } from 'src/user/services/user-session.service';
|
import { UserSessionService } from 'src/auth/service/user-session.service';
|
||||||
import { VerificationService } from 'src/verification/verification.service';
|
|
||||||
import { BusinessException } from 'src/common/exceptions/business.exception';
|
import { BusinessException } from 'src/common/exceptions/business.exception';
|
||||||
import { ErrorCode } from 'src/common/constants/error-codes';
|
import { ErrorCode } from 'src/common/constants/error-codes';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// auth.guard.ts
|
// auth.guard.ts
|
||||||
import { Injectable, CanActivate, ExecutionContext, UnauthorizedException } from '@nestjs/common';
|
import { Injectable, CanActivate, ExecutionContext, UnauthorizedException } from '@nestjs/common';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { UserSessionService } from 'src/user/services/user-session.service';
|
import { UserSessionService } from 'src/auth/service/user-session.service';
|
||||||
import { UserService } from 'src/user/user.service';
|
import { UserService } from 'src/user/user.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { UserSession } from '../entities/user-session.entity';
|
import { UserSession } from '../entity/user-session.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -3,17 +3,15 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
import { User } from './entities/user.entity';
|
import { User } from './entities/user.entity';
|
||||||
import { UserController } from './user.controller';
|
import { UserController } from './user.controller';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
import { UserSession } from './entities/user-session.entity';
|
|
||||||
import { AuthModule } from 'src/auth/auth.module';
|
import { AuthModule } from 'src/auth/auth.module';
|
||||||
import { UserSessionService } from './services/user-session.service';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([User, UserSession]),
|
TypeOrmModule.forFeature([User]),
|
||||||
forwardRef(() => AuthModule), // 解决循环依赖问题
|
forwardRef(() => AuthModule), // 解决循环依赖问题
|
||||||
],
|
],
|
||||||
controllers: [UserController],
|
controllers: [UserController],
|
||||||
providers: [UserService, UserSessionService],
|
providers: [UserService],
|
||||||
exports: [UserService, UserSessionService],
|
exports: [UserService],
|
||||||
})
|
})
|
||||||
export class UserModule {}
|
export class UserModule { }
|
||||||
|
|||||||
Reference in New Issue
Block a user