connection base prisma + postgres + login ok
This commit is contained in:
24
src/providers/AuthProvider.tsx
Normal file
24
src/providers/AuthProvider.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
'use client';
|
||||
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { SessionProvider } from 'next-auth/react';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
|
||||
const AuthContext = createContext<any>(null);
|
||||
|
||||
function AuthInner({ children }: { children: React.ReactNode }) {
|
||||
const auth = useAuth();
|
||||
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>;
|
||||
}
|
||||
|
||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
return (
|
||||
<SessionProvider>
|
||||
<AuthInner>{children}</AuthInner>
|
||||
</SessionProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export function useAuthContext() {
|
||||
return useContext(AuthContext);
|
||||
}
|
||||
33
src/providers/ProjectProvider.tsx
Normal file
33
src/providers/ProjectProvider.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
'use client';
|
||||
|
||||
import React, { createContext, useContext } from 'react';
|
||||
import { BookProject, UserProfile } from '@/lib/types';
|
||||
|
||||
interface ProjectContextType {
|
||||
project: BookProject;
|
||||
user: UserProfile;
|
||||
projectId: string;
|
||||
currentChapterId: string;
|
||||
setCurrentChapterId: (id: string) => void;
|
||||
updateProject: (updates: Partial<BookProject>) => void;
|
||||
updateChapter: (chapterId: string, data: any) => void;
|
||||
incrementUsage: () => void;
|
||||
}
|
||||
|
||||
const ProjectContext = createContext<ProjectContextType | null>(null);
|
||||
|
||||
export function ProjectProvider({
|
||||
value,
|
||||
children,
|
||||
}: {
|
||||
value: ProjectContextType;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return <ProjectContext.Provider value={value}>{children}</ProjectContext.Provider>;
|
||||
}
|
||||
|
||||
export function useProjectContext(): ProjectContextType {
|
||||
const ctx = useContext(ProjectContext);
|
||||
if (!ctx) throw new Error('useProjectContext must be used within ProjectProvider');
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user