diff --git a/views/TokenGate.tsx b/views/TokenGate.tsx index f5e251f..845f5ea 100644 --- a/views/TokenGate.tsx +++ b/views/TokenGate.tsx @@ -3,7 +3,7 @@ import { validateToken } from '../services/githubService'; import { signInWithGitHub } from '../services/firebaseService'; import { GitHubUser } from '../types'; import { Button } from '../components/Button'; -import { Github } from 'lucide-react'; +import { Github, Key } from 'lucide-react'; interface TokenGateProps { onSuccess: (token: string, user: GitHubUser) => void; @@ -12,6 +12,8 @@ interface TokenGateProps { export const TokenGate: React.FC = ({ onSuccess }) => { const [error, setError] = useState(''); const [loading, setLoading] = useState(false); + const [showPatInput, setShowPatInput] = useState(false); + const [patToken, setPatToken] = useState(''); const handleGitHubLogin = async () => { setError(''); @@ -47,6 +49,29 @@ export const TokenGate: React.FC = ({ onSuccess }) => { } }; + const handlePatLogin = async () => { + setError(''); + + if (!patToken.trim()) { + setError('Please enter a Personal Access Token'); + return; + } + + setLoading(true); + + try { + // Validate token and get user data from GitHub API + const user = await validateToken(patToken.trim()); + onSuccess(patToken.trim(), user); + } catch (err: unknown) { + console.error('PAT login error:', err); + const message = err instanceof Error ? err.message : 'Failed to authenticate with PAT'; + setError(message); + } finally { + setLoading(false); + } + }; + return (
@@ -67,15 +92,90 @@ export const TokenGate: React.FC = ({ onSuccess }) => {
)} - + {!showPatInput ? ( + <> + + +
+
+
+
+
+ + Or + +
+
+ + + + ) : ( + <> +
+ + setPatToken(e.target.value)} + onKeyDown={(e) => e.key === 'Enter' && handlePatLogin()} + placeholder="ghp_xxxxxxxxxxxxxxxxxxxx" + className="w-full px-3 py-2 border border-slate-300 dark:border-slate-600 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-slate-700 dark:text-slate-100" + disabled={loading} + /> +

+ + Create a token + + {' '}with repo and read:user scopes. +

+
+ + + + + + )}

By signing in, you grant access to your public and private repositories.