Skip to content

Commit

Permalink
feat : 유저 로그아웃 시 해당 유저 토큰 데이터 만료 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
GeunH committed Dec 1, 2023
1 parent cd0c7b3 commit 437b7e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion be/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import { AuthRepository } from "./auth.repository";
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy, AuthRepository],
exports: [PassportModule],
exports: [PassportModule, AuthService],
})
export class AuthModule { }
4 changes: 4 additions & 0 deletions be/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class AuthService {
}
}

async logout(id: number) {
await this.authRepository.delete({ id: id });
}

async NaverAuth(authorization: string) {
if (!authorization) {
throw new HttpException(
Expand Down
2 changes: 1 addition & 1 deletion be/src/auth/entity/auth.refreshtoken.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Entity, Column, PrimaryColumn } from 'typeorm';

@Entity("AuthToken")
@Entity("auth_token")
export class AuthRefreshTokenEntity {
@PrimaryColumn()
id: number;
Expand Down
18 changes: 10 additions & 8 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AwsService } from "src/aws/aws.service";
import { v4 } from "uuid";
import { User } from "./entities/user.entity";
import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity";
import { AuthService } from "src/auth/auth.service";

@Injectable()
export class UserService {
Expand All @@ -26,8 +27,9 @@ export class UserService {
private userFollowListRepositoy: UserFollowListRepository,
private reviewRepository: ReviewRepository,
private userWishRestaurantListRepository: UserWishRestaurantListRepository,
private awsService: AwsService
) {}
private awsService: AwsService,
private authService: AuthService
) { }
async signup(userInfoDto: UserInfoDto) {
userInfoDto.password = await hashPassword(userInfoDto.password);
const user = {
Expand All @@ -38,11 +40,11 @@ export class UserService {
if (userInfoDto.profileImage) {
const uuid = v4();
user.profileImage = `profile/images/${uuid}.png`;
}
}

const newUser = this.usersRepository.create(user);
await this.usersRepository.createUser(newUser);
if (userInfoDto.profileImage)this.awsService.uploadToS3(user.profileImage, userInfoDto.profileImage);
if (userInfoDto.profileImage) this.awsService.uploadToS3(user.profileImage, userInfoDto.profileImage);
return;
}
async getNickNameAvailability(nickName: UserInfoDto["nickName"]) {
Expand Down Expand Up @@ -77,7 +79,7 @@ export class UserService {
targetInfo.id,
tokenInfo.id
);
if ( restaurantList )result["restaurants"] = restaurantList;
if (restaurantList) result["restaurants"] = restaurantList;
result.profileImage = this.awsService.getImageURL(result.profileImage);
return result;
} catch (err) {
Expand Down Expand Up @@ -290,7 +292,7 @@ export class UserService {
}

async logout(tokenInfo: TokenInfo) {
return await this.usersRepository.logout(tokenInfo.id);
return await this.authService.logout(tokenInfo.id);
}

async deleteUserAccount(tokenInfo: TokenInfo) {
Expand All @@ -306,14 +308,14 @@ export class UserService {
if (userInfoDto.profileImage) {
const uuid = v4();
user.profileImage = `profile/images/${uuid}.png`;
}
}

const newUser = this.usersRepository.create(user);
const result = await this.usersRepository.updateMypageUserInfo(
tokenInfo.id,
newUser
);
if (userInfoDto.profileImage)this.awsService.uploadToS3(user.profileImage, userInfoDto.profileImage);
if (userInfoDto.profileImage) this.awsService.uploadToS3(user.profileImage, userInfoDto.profileImage);
return result;
}
}

0 comments on commit 437b7e6

Please sign in to comment.