feat: integrate Kakao OAuth for user authentication and enhance user repository

- Added Kakao OAuth client implementation for handling authentication flows.
- Updated user repository to support OAuth-based user creation and retrieval.
- Introduced Redis-based session management for OAuth sessions.
- Enhanced in-memory user repository to handle OAuth user data.
- Updated environment configuration files to include new OAuth settings.
- Modified API routes to support Kakao login and registration flows.
- Added Prisma schema updates for user model to accommodate OAuth fields.
- Implemented tests for the new authentication flow and user repository methods.
This commit is contained in:
2025-12-30 02:19:32 +00:00
parent f01a21f2f0
commit 0c1e27ee4a
17 changed files with 893 additions and 6 deletions
+26 -3
View File
@@ -1,27 +1,46 @@
import fastify from 'fastify';
import cors from '@fastify/cors';
import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
import { createRedisConnector, resolveRedisConfigFromEnv } from '@sammo-ts/infra';
import {
createPostgresConnector,
createRedisConnector,
resolvePostgresConfigFromEnv,
resolveRedisConfigFromEnv,
} from '@sammo-ts/infra';
import { resolveGatewayApiConfigFromEnv } from './config.js';
import { createGatewayApiContext } from './context.js';
import { RedisGatewayFlushPublisher } from './auth/flushPublisher.js';
import { createInMemoryUserRepository } from './auth/inMemoryUserRepository.js';
import { KakaoOAuthClient } from './auth/kakaoClient.js';
import { RedisOAuthSessionStore } from './auth/oauthSessionStore.js';
import { createPostgresUserRepository } from './auth/postgresUserRepository.js';
import { RedisGatewaySessionService } from './auth/redisSessionService.js';
import { appRouter } from './router.js';
export const createGatewayApiServer = async () => {
const config = resolveGatewayApiConfigFromEnv();
const postgres = createPostgresConnector(resolvePostgresConfigFromEnv());
const redis = createRedisConnector(resolveRedisConfigFromEnv());
await postgres.connect();
await redis.connect();
const users = createInMemoryUserRepository();
const users = createPostgresUserRepository(postgres.prisma);
const sessions = new RedisGatewaySessionService(redis.client, {
keyPrefix: config.redisKeyPrefix,
sessionTtlSeconds: config.sessionTtlSeconds,
gameSessionTtlSeconds: config.gameSessionTtlSeconds,
});
const flushPublisher = new RedisGatewayFlushPublisher(redis.client, config.flushChannel);
const kakaoClient = new KakaoOAuthClient({
restKey: config.kakaoRestKey,
adminKey: config.kakaoAdminKey,
redirectUri: config.kakaoRedirectUri,
});
const oauthSessions = new RedisOAuthSessionStore(
redis.client,
config.redisKeyPrefix,
config.oauthSessionTtlSeconds
);
const app = fastify({
logger: true,
@@ -43,6 +62,9 @@ export const createGatewayApiServer = async () => {
flushPublisher,
gameTokenSecret: config.gameTokenSecret,
gameSessionTtlSeconds: config.gameSessionTtlSeconds,
kakaoClient,
oauthSessions,
publicBaseUrl: config.publicBaseUrl,
}),
},
});
@@ -53,6 +75,7 @@ export const createGatewayApiServer = async () => {
app.addHook('onClose', async () => {
await redis.disconnect();
await postgres.disconnect();
});
return {