- 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.
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
export interface UserRecord {
|
|
id: string;
|
|
username: string;
|
|
displayName: string;
|
|
roles: string[];
|
|
sanctions: UserSanctions;
|
|
oauthType: 'NONE' | 'KAKAO';
|
|
oauthId?: string;
|
|
email?: string;
|
|
oauthInfo?: UserOAuthInfo;
|
|
passwordHash: string;
|
|
passwordSalt: string;
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface PublicUser {
|
|
id: string;
|
|
username: string;
|
|
displayName: string;
|
|
roles: string[];
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface UserSanctions {
|
|
bannedUntil?: string;
|
|
mutedUntil?: string;
|
|
suspendedUntil?: string;
|
|
warningCount?: number;
|
|
flags?: string[];
|
|
notes?: string;
|
|
}
|
|
|
|
export const toPublicUser = (user: UserRecord): PublicUser => ({
|
|
id: user.id,
|
|
username: user.username,
|
|
displayName: user.displayName,
|
|
roles: user.roles,
|
|
createdAt: user.createdAt,
|
|
});
|
|
|
|
export interface CreateUserInput {
|
|
username: string;
|
|
password: string;
|
|
displayName?: string;
|
|
oauth?: {
|
|
type: 'KAKAO';
|
|
id: string;
|
|
email: string;
|
|
info: UserOAuthInfo;
|
|
};
|
|
}
|
|
|
|
export interface UserRepository {
|
|
findByUsername(username: string): Promise<UserRecord | null>;
|
|
findByOauthId(type: 'KAKAO', oauthId: string): Promise<UserRecord | null>;
|
|
findByEmail(email: string): Promise<UserRecord | null>;
|
|
createUser(input: CreateUserInput): Promise<UserRecord>;
|
|
verifyPassword(user: UserRecord, password: string): Promise<boolean>;
|
|
updatePassword(userId: string, password: string): Promise<void>;
|
|
updateOAuthInfo(userId: string, oauthInfo: UserOAuthInfo): Promise<void>;
|
|
}
|
|
|
|
export interface UserOAuthInfo {
|
|
accessToken?: string;
|
|
refreshToken?: string;
|
|
accessTokenValidUntil?: string;
|
|
refreshTokenValidUntil?: string;
|
|
nextPasswordChange?: string;
|
|
}
|