2022-08-17 00:58:52 -07:00
|
|
|
import { gql, useMutation } from "@apollo/client";
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
FormControl,
|
|
|
|
|
FormHelperText,
|
|
|
|
|
FormLabel,
|
|
|
|
|
Input,
|
|
|
|
|
Modal,
|
|
|
|
|
ModalBody,
|
|
|
|
|
ModalCloseButton,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalHeader,
|
|
|
|
|
ModalOverlay,
|
|
|
|
|
Tab,
|
|
|
|
|
TabList,
|
|
|
|
|
TabPanel,
|
|
|
|
|
TabPanels,
|
|
|
|
|
Tabs,
|
|
|
|
|
} from "@chakra-ui/react";
|
|
|
|
|
import React from "react";
|
2022-08-17 00:58:52 -07:00
|
|
|
import { ErrorMessage, getGraphQLErrorMessage } from "../util";
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
|
|
|
|
|
export default function LoginModal({ isOpen, onClose }) {
|
|
|
|
|
return (
|
|
|
|
|
<Modal isOpen={isOpen} onClose={onClose}>
|
|
|
|
|
<ModalOverlay />
|
|
|
|
|
<ModalContent>
|
|
|
|
|
<ModalHeader>Welcome back to Dress to Impress! ✨</ModalHeader>
|
|
|
|
|
<ModalCloseButton />
|
|
|
|
|
<Tabs>
|
|
|
|
|
<TabList>
|
|
|
|
|
<Tab>Log in</Tab>
|
|
|
|
|
<Tab>Create account</Tab>
|
|
|
|
|
</TabList>
|
|
|
|
|
<TabPanels>
|
|
|
|
|
<TabPanel>
|
|
|
|
|
<ModalBody>
|
2022-08-17 00:58:52 -07:00
|
|
|
<LoginForm onSuccess={() => onClose()} />
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
</ModalBody>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
<TabPanel>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<CreateAccountForm />
|
|
|
|
|
</ModalBody>
|
|
|
|
|
</TabPanel>
|
|
|
|
|
</TabPanels>
|
|
|
|
|
</Tabs>
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 00:58:52 -07:00
|
|
|
function LoginForm({ onSuccess }) {
|
|
|
|
|
const [username, setUsername] = React.useState("");
|
|
|
|
|
const [password, setPassword] = React.useState("");
|
|
|
|
|
|
|
|
|
|
const [
|
|
|
|
|
sendLoginMutation,
|
|
|
|
|
{ loading, error, data, called, reset },
|
|
|
|
|
] = useMutation(gql`
|
|
|
|
|
mutation LoginForm_Login($username: String!, $password: String!) {
|
|
|
|
|
login(username: $username, password: $password) {
|
|
|
|
|
id
|
|
|
|
|
username
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`);
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
|
|
|
|
|
return (
|
2022-08-17 00:58:52 -07:00
|
|
|
<form
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
sendLoginMutation({
|
|
|
|
|
variables: { username, password },
|
|
|
|
|
})
|
|
|
|
|
.then(({ data }) => {
|
|
|
|
|
if (data?.login != null) {
|
|
|
|
|
onSuccess();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {}); // handled in error UI
|
|
|
|
|
}}
|
|
|
|
|
>
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>DTI Username</FormLabel>
|
2022-08-17 00:58:52 -07:00
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
value={username}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setUsername(e.target.value);
|
|
|
|
|
reset();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
<FormHelperText>
|
|
|
|
|
This is separate from your Neopets.com account.
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Box height="4" />
|
|
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>DTI Password</FormLabel>
|
2022-08-17 00:58:52 -07:00
|
|
|
<Input
|
|
|
|
|
type="password"
|
|
|
|
|
value={password}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setPassword(e.target.value);
|
|
|
|
|
reset();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
<FormHelperText>
|
|
|
|
|
Careful, never enter your Neopets password on another site!
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
</FormControl>
|
2022-08-17 00:58:52 -07:00
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
<ErrorMessage marginTop="4">
|
|
|
|
|
Oops, login failed: "{getGraphQLErrorMessage(error)}". Try again?
|
|
|
|
|
</ErrorMessage>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{called && !loading && !error && data?.login == null && (
|
|
|
|
|
<ErrorMessage marginTop="4">
|
|
|
|
|
We couldn't find a match for that username and password. Try again?
|
|
|
|
|
</ErrorMessage>
|
|
|
|
|
)}
|
|
|
|
|
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
<Box marginTop="6" display="flex" alignItems="center">
|
|
|
|
|
<Button size="sm" onClick={() => alert("TODO: Forgot password")}>
|
|
|
|
|
Forgot password?
|
|
|
|
|
</Button>
|
|
|
|
|
<Box flex="1 0 auto" width="4" />
|
2022-08-17 00:58:52 -07:00
|
|
|
<Button type="submit" colorScheme="green" isLoading={loading}>
|
Start building a login form, behind a feature flag
Thinking about longevity, I think I wanna cut Auth0 loose, and just go back to using our own auth.
I had figured at the time that I didn't want to integrate with OpenNeo ID's whole mess, and I didn't want to write a whole new auth system, so Auth0 seemed to make things easier.
But now, it's just kinda a lot to be carrying along an external service as a dependency for login, especially when we've got all the stuff in the database right here. I wanna remove architecture pieces! Get it outta here!
And I'll finally build account creation from the 2020 site while I'm at it, which seemed like it was gonna be a bit of a pain with Auth0 and syncing anyway. (I think at the time I was a bit more optimistic about a full transfer from one system to another, but that's much further off than I realized, and this path will be much better for keeping things in sync.)
2022-08-16 17:34:51 -07:00
|
|
|
Log in
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CreateAccountForm() {
|
|
|
|
|
const onSubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
alert("TODO: Create account!");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form onSubmit={onSubmit}>
|
|
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>DTI Username</FormLabel>
|
|
|
|
|
<Input type="text" />
|
|
|
|
|
<FormHelperText>
|
|
|
|
|
This will be separate from your Neopets.com account.
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Box height="4" />
|
|
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>DTI Password</FormLabel>
|
|
|
|
|
<Input type="password" />
|
|
|
|
|
<FormHelperText>
|
|
|
|
|
Careful, never use your Neopets password for another site!
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Box height="4" />
|
|
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>Confirm DTI Password</FormLabel>
|
|
|
|
|
<Input type="password" />
|
|
|
|
|
<FormHelperText>One more time, to make sure!</FormHelperText>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Box height="4" />
|
|
|
|
|
<FormControl>
|
|
|
|
|
<FormLabel>Email address</FormLabel>
|
|
|
|
|
<Input type="password" />
|
|
|
|
|
<FormHelperText>
|
|
|
|
|
We'll use this in the future if you need to reset your password, or
|
|
|
|
|
for us to contact you about your account. We won't sell this address,
|
|
|
|
|
and we won't send marketing-y emails.
|
|
|
|
|
</FormHelperText>
|
|
|
|
|
</FormControl>
|
|
|
|
|
<Box height="6" />
|
|
|
|
|
<Box display="flex" justifyContent="flex-end">
|
|
|
|
|
<Button type="submit" colorScheme="green">
|
|
|
|
|
Create account
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|