GeezerVison is showing github.com — Merge pull request #1 from aidrivencoder/dev · aidrivencoder/master-git-github@35cdfac
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "firestore": { | | 3 | + "rules": "firebase.rules", | | 4 | + "indexes": "firestore.indexes.json" | | 5 | + } | | 6 | +} |
Collapse file Copy file name to clipboardExpand all lines: firebase.rules +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,5 +54,13 @@ service cloud.firestore { | 54 | 54 | ); | 55 | 55 | allow write: if isAdmin(); | 56 | 56 | } | | 57 | + | | 58 | + // Checkout Sessions collection | | 59 | + match /checkoutSessions/{sessionId} { | | 60 | + allow read: if isAuthenticated() && ( | | 61 | + resource.data.userId == request.auth.uid || isAdmin() | | 62 | + ); | | 63 | + allow write: if isAdmin(); | | 64 | + } | 57 | 65 | } | 58 | | -} | | 66 | +} |
Collapse file Copy file name to clipboard +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "indexes": [], | | 3 | + "fieldOverrides": [] | | 4 | +} |
Collapse file Copy file name to clipboardExpand all lines: package-lock.json +4Lines changed: 4 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +11-7Lines changed: 11 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | "@headlessui/react": "^1.7.17", | 13 | 13 | "@heroicons/react": "^2.0.18", | 14 | 14 | "@mdx-js/react": "^3.0.0", | 15 | | - "@uiw/react-markdown-preview": "^5.0.3", | 16 | | - "@uiw/react-md-editor": "^4.0.1", | 17 | | - "prismjs": "^1.29.0", | 18 | 15 | "@stripe/stripe-js": "^2.1.7", | 19 | 16 | "@tanstack/react-query": "^4.36.1", | | 17 | + "@uiw/react-markdown-preview": "^5.0.3", | | 18 | + "@uiw/react-md-editor": "^4.0.1", | 20 | 19 | "firebase": "^9.23.0", | 21 | 20 | "firebase-admin": "^11.11.0", | 22 | 21 | "firebase-tools": "^12.7.0", | 23 | 22 | "next": "13.4.19", | | 23 | + "prismjs": "^1.29.0", | 24 | 24 | "react": "18.2.0", | 25 | 25 | "react-dom": "18.2.0", | 26 | | - "react-syntax-highlighter": "^15.5.0", | 27 | 26 | "react-error-boundary": "^4.0.11", | | 27 | + "react-markdown": "^9.0.1", | | 28 | + "react-syntax-highlighter": "^15.5.0", | | 29 | + "rehype-prism-plus": "^2.0.0", | | 30 | + "rehype-raw": "^7.0.0", | | 31 | + "remark-gfm": "^4.0.0", | 28 | 32 | "stripe": "^13.9.0", | 29 | 33 | "zustand": "^4.4.3" | 30 | 34 | }, | 31 | 35 | "devDependencies": { | 32 | 36 | "@babel/core": "^7.23.0", | 33 | 37 | "@babel/plugin-proposal-class-properties": "^7.18.6", | 34 | | - "@next/bundle-analyzer": "^13.5.4", | 35 | 38 | "@babel/plugin-proposal-private-methods": "^7.18.6", | 36 | 39 | "@babel/preset-env": "^7.22.20", | | 40 | + "@next/bundle-analyzer": "^13.5.4", | 37 | 41 | "@types/node": "^20.8.4", | 38 | 42 | "@types/prismjs": "^1.26.3", | 39 | | - "@types/react-syntax-highlighter": "^15.5.11", | 40 | 43 | "@types/react": "18.2.0", | 41 | 44 | "@types/react-dom": "18.2.0", | | 45 | + "@types/react-syntax-highlighter": "^15.5.11", | 42 | 46 | "autoprefixer": "^10.4.16", | 43 | 47 | "babel-loader": "^9.1.3", | 44 | 48 | "eslint": "^8.51.0", | 45 | 49 | "eslint-config-next": "13.4.19", | 46 | 50 | "postcss": "^8.4.31", | 47 | | - "tailwindcss": "^3.3.3", | 48 | 51 | "raw-loader": "^4.0.2", | | 52 | + "tailwindcss": "^3.3.3", | 49 | 53 | "typescript": "^5.2.2" | 50 | 54 | } | 51 | 55 | } |
Collapse file Copy file name to clipboard +143Lines changed: 143 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use client'; | | 2 | + | | 3 | +import { useEffect, useState } from 'react'; | | 4 | +import { useRouter } from 'next/navigation'; | | 5 | +import Link from 'next/link'; | | 6 | +import { auth } from '@/lib/firebase/config'; | | 7 | +import { onAuthStateChanged } from 'firebase/auth'; | | 8 | +import { db } from '@/lib/firebase/config'; | | 9 | +import { doc, getDoc } from 'firebase/firestore'; | | 10 | + | | 11 | +interface NavItem { | | 12 | + label: string; | | 13 | + href: string; | | 14 | + icon: string; | | 15 | +} | | 16 | + | | 17 | +const navItems: NavItem[] = [ | | 18 | + { | | 19 | + label: 'Overview', | | 20 | + href: '/admin', | | 21 | + icon: '📊' | | 22 | + }, | | 23 | + { | | 24 | + label: 'Users', | | 25 | + href: '/admin/users', | | 26 | + icon: '👥' | | 27 | + }, | | 28 | + { | | 29 | + label: 'Tutorials', | | 30 | + href: '/admin/tutorials', | | 31 | + icon: '📚' | | 32 | + }, | | 33 | + { | | 34 | + label: 'Subscriptions', | | 35 | + href: '/admin/subscriptions', | | 36 | + icon: '💳' | | 37 | + } | | 38 | +]; | | 39 | + | | 40 | +export default function AdminLayout({ | | 41 | + children, | | 42 | +}: { | | 43 | + children: React.ReactNode; | | 44 | +}) { | | 45 | + const [loading, setLoading] = useState(true); | | 46 | + const [isAdmin, setIsAdmin] = useState(false); | | 47 | + const router = useRouter(); | | 48 | + | | 49 | + useEffect(() => { | | 50 | + const unsubscribe = onAuthStateChanged(auth, async (user) => { | | 51 | + if (!user) { | | 52 | + router.push('/login'); | | 53 | + setLoading(false); | | 54 | + return; | | 55 | + } | | 56 | + | | 57 | + try { | | 58 | + // Check if user has admin role in Firestore | | 59 | + const userDoc = await getDoc(doc(db, 'users', user.uid)); | | 60 | + const userData = userDoc.data(); | | 61 | + | | 62 | + if (!userData || userData.role !== 'admin') { | | 63 | + router.push('/login'); | | 64 | + setLoading(false); | | 65 | + return; | | 66 | + } | | 67 | + | | 68 | + setIsAdmin(true); | | 69 | + } catch (error) { | | 70 | + console.error('Error checking admin status:', error); | | 71 | + router.push('/login'); | | 72 | + } finally { | | 73 | + setLoading(false); | | 74 | + } | | 75 | + }); | | 76 | + | | 77 | + return () => unsubscribe(); | | 78 | + }, [router]); | | 79 | + | | 80 | + if (loading) { | | 81 | + return ( | | 82 | + <div className="flex items-center justify-center min-h-screen"> | | 83 | + <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900"></div> | | 84 | + </div> | | 85 | + ); | | 86 | + } | | 87 | + | | 88 | + if (!isAdmin) { | | 89 | + return null; | | 90 | + } | | 91 | + | | 92 | + return ( | | 93 | + <div className="min-h-screen bg-gray-100"> | | 94 | + <div className="flex"> | | 95 | + {/* Admin Sidebar */} | | 96 | + <div className="w-64 min-h-screen bg-white shadow-lg"> | | 97 | + <div className="p-6 border-b"> | | 98 | + <h2 className="text-xl font-bold text-gray-800">Admin Dashboard</h2> | | 99 | + </div> | | 100 | + <nav className="mt-6"> | | 101 | + {navItems.map((item) => ( | | 102 | + <Link | | 103 | + key={item.href} | | 104 | + href={item.href} | | 105 | + className={`flex items-center px-6 py-3 text-gray-700 hover:bg-gray-100 hover:text-gray-900 transition-colors duration-200 ${ | | 106 | + typeof window !== 'undefined' && window.location.pathname === item.href | | 107 | + ? 'bg-gray-100 text-gray-900' | | 108 | + : '' | | 109 | + }`} | | 110 | + > | | 111 | + <span className="mr-3">{item.icon}</span> | | 112 | + {item.label} | | 113 | + </Link> | | 114 | + ))} | | 115 | + </nav> | | 116 | + | | 117 | + <div className="absolute bottom-0 w-64 p-6 border-t"> | | 118 | + <div className="flex items-center"> | | 119 | + <div className="ml-3"> | | 120 | + <p className="text-sm font-medium text-gray-700"> | | 121 | + {auth.currentUser?.email} | | 122 | + </p> | | 123 | + <button | | 124 | + onClick={() => auth.signOut()} | | 125 | + className="text-sm text-red-600 hover:text-red-800" | | 126 | + > | | 127 | + Sign Out | | 128 | + </button> | | 129 | + </div> | | 130 | + </div> | | 131 | + </div> | | 132 | + </div> | | 133 | + | | 134 | + {/* Main Content */} | | 135 | + <div className="flex-1 overflow-auto"> | | 136 | + <div className="p-6"> | | 137 | + {children} | | 138 | + </div> | | 139 | + </div> | | 140 | + </div> | | 141 | + </div> | | 142 | + ); | | 143 | +} |
|