feat: AI quiz generation per lesson + hide edit buttons for non-authors
- Generate unique quiz for each lesson using OpenRouter API - Parse lesson content (TipTap JSON) and send to AI for question generation - Cache quiz in database to avoid regeneration - Hide Edit/Delete buttons if current user is not course author - Add backendUser to auth context for proper authorization checks - Show certificate button prominently when course is completed Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -6,8 +6,17 @@ import { getSupabase } from '@/lib/supabase';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { api, setApiToken } from '@/lib/api';
|
||||
|
||||
interface BackendUser {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
avatarUrl: string | null;
|
||||
subscriptionTier: string;
|
||||
}
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null;
|
||||
backendUser: BackendUser | null;
|
||||
session: Session | null;
|
||||
loading: boolean;
|
||||
signUp: (email: string, password: string, name: string) => Promise<{ error: Error | null }>;
|
||||
@ -20,6 +29,7 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [backendUser, setBackendUser] = useState<BackendUser | null>(null);
|
||||
const [session, setSession] = useState<Session | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const router = useRouter();
|
||||
@ -64,8 +74,9 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const tryExchange = () => {
|
||||
api
|
||||
.exchangeToken(session.access_token)
|
||||
.then(({ accessToken }) => {
|
||||
.then(({ accessToken, user: backendUserData }) => {
|
||||
setApiToken(accessToken);
|
||||
setBackendUser(backendUserData);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
@ -152,6 +163,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
user,
|
||||
backendUser,
|
||||
session,
|
||||
loading,
|
||||
signUp,
|
||||
|
||||
Reference in New Issue
Block a user