Skip to content

Commit

Permalink
feat: add demo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed Dec 17, 2023
1 parent 9966541 commit 535d911
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Authentication.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Tab } from "@headlessui/react";
import { DemoModeButton } from "./DemoModeButton";
import { LoginForm } from "./authentication/LoginForm";
import { RegisterForm } from "./authentication/RegisterForm";

Expand All @@ -7,7 +8,7 @@ function classNames(...classes: string[]) {
}

export const Authentication = () => (
<section className="flex flex-col flex-grow items-center py-12 bg-gray-50">
<section className="flex flex-col flex-grow gap-8 items-center py-12 bg-gray-50">
<div className="mx-auto max-w-4xl p-4 bg-white rounded-md shadow-md flex flex-col gap-4">
<Tab.Group>
<Tab.List className="-mb-px flex">
Expand All @@ -16,7 +17,7 @@ export const Authentication = () => (
<span
className={classNames(
selected
? "border-indigo-500 text-indigo-600"
? "border-sky-500 text-sky-600"
: "border-gray-200 text-gray-500 hover:border-gray-300 hover:text-gray-700",
"whitespace-nowrap border-b-2 text-sm font-medium w-full text-center pb-4 block",
)}
Expand All @@ -30,7 +31,7 @@ export const Authentication = () => (
<span
className={classNames(
selected
? "border-indigo-500 text-indigo-600"
? "border-sky-500 text-sky-600"
: "border-gray-200 text-gray-500 hover:border-gray-300 hover:text-gray-700",
"whitespace-nowrap border-b-2 text-sm font-medium w-full text-center pb-4 block",
)}
Expand All @@ -50,5 +51,6 @@ export const Authentication = () => (
</Tab.Panels>
</Tab.Group>
</div>
<DemoModeButton />
</section>
);
14 changes: 14 additions & 0 deletions src/DemoModeButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { signInAnonymously } from "firebase/auth";
import { auth } from "./firebaseConfig";

// Uses firebase anonymous authentication to log in as a demo user
export const DemoModeButton = () => {
return (
<button
className="text-sky-500 underline"
onClick={() => signInAnonymously(auth)}
>
Demo mode
</button>
);
};
2 changes: 1 addition & 1 deletion src/SessionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SessionPicker = () => {
const [selected, setSelected] = useState<string[]>([]);
const { sessions, setSessions } = useContext(SessionContext);
const { user } = useContext(UserContext);
const uuid = user?.uid;
const uuid = user?.isAnonymous ? "6U4S2ruwXMPrULj50b9uLpsaRk53" : user?.uid;

useEffect(() => {
async function fetchSnapshot() {
Expand Down
3 changes: 2 additions & 1 deletion src/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { auth } from "./firebaseConfig";
export const UserMenu = () => {
const { user } = useContext(UserContext);
const isAuthenticated = user?.uid;
const isAnonymous = user?.isAnonymous;
return (
<div className="flex flex-row gap-4 items-center">
{isAuthenticated && (
<>
<UploadModal />
{!isAnonymous && <UploadModal />}
<button onClick={() => auth.signOut()} className="btn">
Logout
</button>
Expand Down

0 comments on commit 535d911

Please sign in to comment.