Skip to main content
Glama
LoginPage.tsx8.28 kB
import React, { useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { MessageSquare, Mail, Lock, ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useAuth } from '@/context/AuthContext'; const LoginPage: React.FC = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const { login, loginWithGoogle } = useAuth(); const navigate = useNavigate(); const handleEmailLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setIsLoading(true); try { await login(email, password); // Redirect based on role const isAdmin = email === 'admin@mcpchat.com'; navigate(isAdmin ? '/admin/dashboard' : '/dashboard'); } catch (error) { setError('Invalid email or password. Please try again.'); } finally { setIsLoading(false); } }; const handleGoogleLogin = async () => { setError(''); try { await loginWithGoogle(); navigate('/dashboard'); } catch (error) { setError('Failed to sign in with Google. Please try again.'); } }; return ( <div className="min-h-screen bg-gray-50 flex flex-col justify-center py-12 sm:px-6 lg:px-8"> <div className="sm:mx-auto sm:w-full sm:max-w-md"> <Link to="/" className="flex items-center justify-center"> <div className="bg-primary text-white p-2 rounded-md"> <MessageSquare className="h-6 w-6" /> </div> <span className="ml-2 text-xl font-bold">MCP Chat Support</span> </Link> <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900"> Sign in to your account </h2> <p className="mt-2 text-center text-sm text-gray-600"> Or{' '} <Link to="/signup" className="font-medium text-primary hover:text-primary-dark"> create a new account </Link> </p> </div> <div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md"> <div className="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10"> {error && ( <div className="mb-4 bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md"> {error} </div> )} <form className="space-y-6" onSubmit={handleEmailLogin}> <div> <label htmlFor="email" className="block text-sm font-medium text-gray-700"> Email address </label> <div className="mt-1 relative rounded-md shadow-sm"> <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> <Mail className="h-5 w-5 text-gray-400" /> </div> <input id="email" name="email" type="email" autoComplete="email" required value={email} onChange={(e) => setEmail(e.target.value)} className="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-primary focus:border-primary" placeholder="Email address" /> </div> </div> <div> <label htmlFor="password" className="block text-sm font-medium text-gray-700"> Password </label> <div className="mt-1 relative rounded-md shadow-sm"> <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none"> <Lock className="h-5 w-5 text-gray-400" /> </div> <input id="password" name="password" type="password" autoComplete="current-password" required value={password} onChange={(e) => setPassword(e.target.value)} className="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-primary focus:border-primary" placeholder="Password" /> </div> </div> <div className="flex items-center justify-between"> <div className="flex items-center"> <input id="remember-me" name="remember-me" type="checkbox" className="h-4 w-4 text-primary focus:ring-primary border-gray-300 rounded" /> <label htmlFor="remember-me" className="ml-2 block text-sm text-gray-700"> Remember me </label> </div> <div className="text-sm"> <a href="#" className="font-medium text-primary hover:text-primary-dark"> Forgot your password? </a> </div> </div> <div> <Button type="submit" className="w-full flex justify-center" disabled={isLoading} > {isLoading ? ( <div className="animate-spin rounded-full h-5 w-5 border-t-2 border-b-2 border-white"></div> ) : 'Sign in'} </Button> </div> </form> <div className="mt-6"> <div className="relative"> <div className="absolute inset-0 flex items-center"> <div className="w-full border-t border-gray-300"></div> </div> <div className="relative flex justify-center text-sm"> <span className="px-2 bg-white text-gray-500">Or continue with</span> </div> </div> <div className="mt-6"> <Button variant="outline" className="w-full" onClick={handleGoogleLogin} > <svg className="h-5 w-5 mr-2" viewBox="0 0 24 24"> <g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)"> <path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z" /> <path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z" /> <path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z" /> <path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z" /> </g> </svg> Sign in with Google </Button> </div> </div> <div className="mt-6 flex items-center justify-center"> <Link to="/" className="text-sm text-gray-600 hover:text-gray-900 flex items-center"> <ArrowLeft className="h-4 w-4 mr-1" /> Back to home </Link> </div> </div> </div> </div> ); }; export default LoginPage;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ChiragPatankar/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server