Skip to content

Commit

Permalink
fix(log): Fixed log crashing when user was not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbenton committed Apr 11, 2024
1 parent 30d710f commit e425f16
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function GameLogEntry(props: GameLogEntryProps) {
);

const logCreatorName = useStore(
(store) => store.users.userMap[log.uid].doc?.displayName
(store) => store.users.userMap[log.uid]?.doc?.displayName
);

const isYourEntry = log.characterId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Button,
Dialog,
DialogActions,
DialogContent,
TextField,
} from "@mui/material";
import { DialogTitleWithCloseButton } from "components/shared/DialogTitleWithCloseButton";
import { loginWithToken } from "lib/auth.lib";
import { useState } from "react";

export interface CustomTokenDialogProps {
open: boolean;
onClose: () => void;
}

export function CustomTokenDialog(props: CustomTokenDialogProps) {
const { open, onClose } = props;

const [token, setToken] = useState("");
const handleLogin = () => {
loginWithToken(token)
.then(() => {
location.reload();
})
.catch((error) => {
console.error(error);
});
};

return (
<Dialog open={open} onClose={onClose}>
<DialogTitleWithCloseButton onClose={onClose}>
Login with Custom Token
</DialogTitleWithCloseButton>
<DialogContent>
<TextField
sx={{ mt: 0.5 }}
label={"Token"}
value={token}
onChange={(evt) => setToken(evt.target.value)}
/>
</DialogContent>
<DialogActions>
<Button color={"inherit"} onClick={onClose}>
Cancel
</Button>
<Button variant={"contained"} onClick={handleLogin}>
Login
</Button>
</DialogActions>
</Dialog>
);
}
17 changes: 17 additions & 0 deletions src/components/shared/Layout/nav/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { useStore } from "stores/store";
import { AUTH_STATE } from "stores/auth/auth.slice.type";
import { UserNameDialog } from "components/shared/UserNameDialog";
import UsernameIcon from "@mui/icons-material/AccountCircle";
import TokenIcon from "@mui/icons-material/Contacts";
import { CustomTokenDialog } from "./CustomTokenDialog/CustomTokenDialog";

export function SettingsMenu() {
const [menuOpen, setMenuOpen] = useState<boolean>(false);
Expand All @@ -46,6 +48,7 @@ export function SettingsMenu() {

const [betaTestsOpen, setBetaTestsOpen] = useState(false);
const [usernameDialogOpen, setUsernameDialogOpen] = useState(false);
const [customTokenDialogOpen, setCustomTokenDialogOpen] = useState(false);

const isMobile = useIsMobile();

Expand Down Expand Up @@ -178,6 +181,14 @@ export function SettingsMenu() {
<ListItemText>Switch System</ListItemText>
</MenuItem>
)}
{isLocal && (
<MenuItem onClick={() => setCustomTokenDialogOpen(true)}>
<ListItemIcon>
<TokenIcon />
</ListItemIcon>
<ListItemText>Login with Custom Token</ListItemText>
</MenuItem>
)}
</Menu>
<AccessibilitySettingsDialog
open={accessibilitySettingsOpen}
Expand All @@ -192,6 +203,12 @@ export function SettingsMenu() {
handleClose={() => setUsernameDialogOpen(false)}
updating
/>
{isLocal && (
<CustomTokenDialog
open={customTokenDialogOpen}
onClose={() => setCustomTokenDialogOpen(false)}
/>
)}
</>
);
}
14 changes: 14 additions & 0 deletions src/lib/auth.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
isSignInWithEmailLink,
onAuthStateChanged,
sendSignInLinkToEmail,
signInWithCustomToken,
signInWithEmailLink,
signInWithPopup,
signOut,
Expand Down Expand Up @@ -30,6 +31,19 @@ export function loginWithGoogle() {
});
}

export function loginWithToken(token: string) {
return new Promise((resolve, reject) => {
signInWithCustomToken(firebaseAuth, token)
.then(() => {
resolve(true);
})
.catch((e) => {
console.error(e);
reject(e);
});
});
}

export function sendMagicEmailLink(
email: string,
name?: string
Expand Down

0 comments on commit e425f16

Please sign in to comment.