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
+39 -2
View File
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
import { InMemoryGatewaySessionService } from '../src/auth/inMemorySessionService.js';
import { createInMemoryUserRepository } from '../src/auth/inMemoryUserRepository.js';
import { InMemoryOAuthSessionStore } from '../src/auth/oauthSessionStore.js';
import { createGatewayApiContext } from '../src/context.js';
import { appRouter } from '../src/router.js';
@@ -14,21 +15,57 @@ const buildCaller = () => {
const flushPublisher = {
publishUserFlush: async () => {},
};
return appRouter.createCaller(
const oauthSessions = new InMemoryOAuthSessionStore();
const kakaoClient = {
buildAuthUrl: () => '',
exchangeCode: async () => {
throw new Error('not used');
},
refreshToken: async () => {
throw new Error('not used');
},
signup: async () => ({ id: '1' }),
getMe: async () => ({
id: '1',
kakaoAccount: {
hasEmail: true,
email: 'tester@example.com',
isEmailValid: true,
isEmailVerified: true,
},
}),
sendTalkMessage: async () => {},
};
const caller = appRouter.createCaller(
createGatewayApiContext({
users,
sessions,
flushPublisher,
gameTokenSecret: 'test-secret',
gameSessionTtlSeconds: 600,
kakaoClient,
oauthSessions,
publicBaseUrl: 'http://localhost',
})
);
return { caller, oauthSessions };
};
describe('gateway auth flow', () => {
it('registers and issues a game session', async () => {
const caller = buildCaller();
const { caller, oauthSessions } = buildCaller();
const oauthSession = await oauthSessions.createSession({
mode: 'login',
kakaoId: '1',
email: 'tester@example.com',
accessToken: 'token',
refreshToken: 'refresh',
accessTokenValidUntil: new Date().toISOString(),
refreshTokenValidUntil: new Date().toISOString(),
createdAt: new Date().toISOString(),
});
const register = await caller.auth.register({
oauthSessionId: oauthSession.id,
username: 'tester',
password: 'secretpass',
displayName: 'Tester',