Beta and env changes
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
Disallow: /
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||
import { AuthProvider } from './contexts/AuthContext';
|
||||
import BetaPasswordProtection from './components/BetaPasswordProtection';
|
||||
import Navbar from './components/Navbar';
|
||||
import Footer from './components/Footer';
|
||||
import Home from './pages/Home';
|
||||
@@ -22,12 +23,13 @@ import './App.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<Router>
|
||||
<div className="d-flex flex-column min-vh-100">
|
||||
<Navbar />
|
||||
<main className="flex-grow-1">
|
||||
<Routes>
|
||||
<BetaPasswordProtection>
|
||||
<AuthProvider>
|
||||
<Router>
|
||||
<div className="d-flex flex-column min-vh-100">
|
||||
<Navbar />
|
||||
<main className="flex-grow-1">
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
@@ -104,6 +106,7 @@ function App() {
|
||||
</div>
|
||||
</Router>
|
||||
</AuthProvider>
|
||||
</BetaPasswordProtection>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
135
frontend/src/components/BetaPasswordProtection.tsx
Normal file
135
frontend/src/components/BetaPasswordProtection.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
|
||||
interface BetaPasswordProtectionProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const BetaPasswordProtection: React.FC<BetaPasswordProtectionProps> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Check if user already has valid beta access
|
||||
const betaToken = localStorage.getItem("betaAccess");
|
||||
if (betaToken) {
|
||||
// Verify the stored token is still valid
|
||||
verifyBetaAccess(betaToken);
|
||||
} else {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const verifyBetaAccess = async (token: string) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.REACT_APP_API_URL}/beta/verify`,
|
||||
{
|
||||
headers: {
|
||||
"X-Beta-Password": token,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
setIsAuthenticated(true);
|
||||
} else {
|
||||
localStorage.removeItem("betaAccess");
|
||||
}
|
||||
} catch (error) {
|
||||
localStorage.removeItem("betaAccess");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
|
||||
if (!password) {
|
||||
setError("Please enter a password");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${process.env.REACT_APP_API_URL}/beta/verify`,
|
||||
{
|
||||
headers: {
|
||||
"X-Beta-Password": password,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
localStorage.setItem("betaAccess", password);
|
||||
setIsAuthenticated(true);
|
||||
} else {
|
||||
setError("Invalid beta password");
|
||||
}
|
||||
} catch (error) {
|
||||
setError("Failed to verify beta password");
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-vh-100 d-flex align-items-center justify-content-center">
|
||||
<div className="spinner-border text-primary" role="status">
|
||||
<span className="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return (
|
||||
<div className="min-vh-100 d-flex align-items-center justify-content-center bg-light">
|
||||
<div
|
||||
className="card shadow"
|
||||
style={{ maxWidth: "400px", width: "100%" }}
|
||||
>
|
||||
<div className="card-body p-5">
|
||||
<h2 className="text-center mb-4">Beta Access Required</h2>
|
||||
<p className="text-muted text-center mb-4">
|
||||
This site is currently in beta testing. Please enter the beta
|
||||
password to continue.
|
||||
</p>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="betaPassword" className="form-label">
|
||||
Beta Password
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
className="form-control"
|
||||
id="betaPassword"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Enter beta password"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
{error && (
|
||||
<div className="alert alert-danger" role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
<button type="submit" className="btn btn-primary w-100">
|
||||
Access Beta
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default BetaPasswordProtection;
|
||||
Reference in New Issue
Block a user