@restnfeel/agentc-starter-kit
Version:
한국어 기업용 CMS 모듈 - Task Master AI와 함께 빠르게 웹사이트를 구현할 수 있는 재사용 가능한 컴포넌트 시스템
59 lines (51 loc) • 1.47 kB
text/typescript
import { User } from "../../types";
import { SignInOptions } from "../AuthProvider";
// NextAuth session type (simplified)
interface NextAuthSession {
user?: {
id?: string;
email?: string;
name?: string;
image?: string;
};
}
// Helper function to convert NextAuth user to our User type
const convertNextAuthUser = (
nextAuthUser: NextAuthSession["user"]
): User | null => {
if (!nextAuthUser) return null;
return {
id: nextAuthUser.id || "",
email: nextAuthUser.email || "",
name: nextAuthUser.name || "",
avatar_url: nextAuthUser.image,
role: "customer", // Default role, can be customized
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
};
// NextAuth adapter for AuthProvider
export const createNextAuthAdapter = (nextAuth?: {
getSession: () => Promise<NextAuthSession | null>;
signIn: (provider?: string, options?: SignInOptions) => Promise<void>;
signOut: () => Promise<void>;
}) => {
if (!nextAuth) {
console.warn("NextAuth not provided to adapter");
return {};
}
return {
getSession: async () => {
const session = await nextAuth.getSession();
return {
user: convertNextAuthUser(session?.user),
};
},
signInAdapter: async (provider?: string, options?: SignInOptions) => {
await nextAuth.signIn(provider, options);
},
signOutAdapter: async () => {
await nextAuth.signOut();
},
};
};