()
| 14 | import { sessionAtom } from 'state' |
| 15 | |
| 16 | export default function Register() { |
| 17 | const [error, setError] = useState<string | undefined>() |
| 18 | const [open, setOpen] = useState(false) |
| 19 | const setSessionData = useSetAtom(sessionAtom) |
| 20 | |
| 21 | useEffect(() => { |
| 22 | const restoreSession = async () => { |
| 23 | const session = await getSession() |
| 24 | // Check if the response was a 404 |
| 25 | if (session === undefined) { |
| 26 | setSessionData(undefined) |
| 27 | setOpen(true) |
| 28 | } else { |
| 29 | setSessionData(session) |
| 30 | setOpen(false) |
| 31 | } |
| 32 | } |
| 33 | const errorMessage = Cookies.get('error') |
| 34 | if (errorMessage) { |
| 35 | setError(errorMessage) |
| 36 | Cookies.remove('error') |
| 37 | } |
| 38 | restoreSession().catch((error_: unknown) => console.error(error_)) |
| 39 | }, [setSessionData]) |
| 40 | |
| 41 | const title = 'Login' |
| 42 | |
| 43 | return ( |
| 44 | <Dialog |
| 45 | open={open} |
| 46 | onOpenChange={(op: boolean) => { |
| 47 | // TODO: should reload the page when in mid-registration |
| 48 | console.log(op) |
| 49 | }} |
| 50 | > |
| 51 | <DialogContent noClose className='sm:max-w-[425px]'> |
| 52 | <DialogHeader> |
| 53 | <DialogTitle>{title}</DialogTitle> |
| 54 | {error ? ( |
| 55 | <DialogDescription className='mb-2 text-red-500 dark:text-red-400'> |
| 56 | {error} |
| 57 | </DialogDescription> |
| 58 | ) : ( |
| 59 | <DialogDescription> |
| 60 | To enforce usage quotas an account is required. |
| 61 | </DialogDescription> |
| 62 | )} |
| 63 | </DialogHeader> |
| 64 | <div className='items-center'> |
| 65 | <Button asChild> |
| 66 | <a href='/v1/login'> |
| 67 | <GitHubLogoIcon className='mr-2' /> Login with GitHub |
| 68 | </a> |
| 69 | </Button> |
| 70 | </div> |
| 71 | </DialogContent> |
| 72 | </Dialog> |
| 73 | ) |
nothing calls this directly
no test coverage detected