add user module and jwt
This commit is contained in:
parent
ddb436cb9a
commit
9d23757f45
@ -90,6 +90,7 @@ export class PostEntity extends BaseEntity {
|
||||
@OneToMany(() => CommentEntity, (comment) => comment.post, { cascade: true })
|
||||
comments: Relation<CommentEntity>[];
|
||||
|
||||
@Expose()
|
||||
@ManyToOne(() => UserEntity, (user) => user.posts, {
|
||||
nullable: false,
|
||||
onDelete: 'CASCADE',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { join } from 'path';
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
|
||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
||||
@ -11,7 +11,7 @@ import { TypeormMigrationRun } from '@/modules/database/commands/typeorm.migrati
|
||||
import { DBOptions } from '@/modules/database/types';
|
||||
|
||||
@Injectable()
|
||||
export class AutoMigrateResolver {
|
||||
export class AutoMigrateResolver implements OnModuleInit {
|
||||
constructor(private ref: ModuleRef) {}
|
||||
|
||||
async onModuleInit() {
|
||||
|
@ -50,7 +50,7 @@ export class UserEntity {
|
||||
* 用户手机号
|
||||
*/
|
||||
@Expose()
|
||||
@Column({ comment: '用户手机号', length: 64, nullable: false, unique: true })
|
||||
@Column({ comment: '用户手机号', length: 64, nullable: true, unique: true })
|
||||
phone?: string;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { BadGatewayException, ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
|
||||
import { validateOrReject } from 'class-validator';
|
||||
|
||||
@ -14,7 +14,7 @@ export class LocalAuthGuard extends AuthGuard('local') {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
try {
|
||||
await validateOrReject(plainToClass(CredentialDto, request.body), {
|
||||
await validateOrReject(plainToInstance(CredentialDto, request.body), {
|
||||
validationError: { target: false },
|
||||
});
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user