Skip to content

Commit

Permalink
Merge pull request #77 from Wakttu/dev
Browse files Browse the repository at this point in the history
fix : redis setting and user reload
  • Loading branch information
iqeq1945 authored Nov 20, 2024
2 parents 6076a71 + 7602ecd commit c95b6c9
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@ export class AppController {
}

@Get('/test')
getSession(@Req() req: Request): any {
const user = this.appService.findUser(req.session.user);
if (!user) req.session.destroy(() => {});
req.session.user = user;
async getSession(@Req() req: Request) {
const { status, user } = await this.appService.findUser(req.session.user);
if (!status) req.session.destroy(() => {});
if (user) req.session.user = user;
return req.session;
}

4 changes: 2 additions & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@ export class AppService {
}

async findUser(user: any) {
if (!user) return false;
if (!user || !user.id) return { status: 400, message: 'Not session' };
const data = await this.userService.findById(user.id);
return !!data;
return { status: !!data, message: 'user 정보 확인', user: data };
}
}
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ async function bootstrap() {
database: parseInt(process.env.REDIS_DB || '0', 10), // 문자열을 숫자로 변환
});

if (process.env.NODE_ENV === 'jogong') {
if (process.env.NODE_ENV !== 'development') {
redisClient.on('error', (err) => console.error('Redis Client Error', err));
await redisClient.connect(); // Redis v4에서는 connect()를 호출해야 합니다.
}
@@ -38,7 +38,7 @@ async function bootstrap() {

const sessionMiddleware = session({
store:
process.env.NODE_ENV === 'jogong'
process.env.NODE_ENV !== 'development'
? new RedisStore({ client: redisClient })
: new MongoStore({
uri: process.env.SESSION_DB_URI,

0 comments on commit c95b6c9

Please sign in to comment.