Improve auth and seeds (#352)

* Improve seeds

* Autofill password on local environment

* Fix PR

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Félix Malfait
2023-06-21 23:47:24 -07:00
committed by GitHub
parent df6376dce0
commit 3c1851b3c9
6 changed files with 44 additions and 26 deletions

View File

@ -1,6 +1,6 @@
import { atom } from 'recoil';
export const authFlowUserEmailState = atom<string>({
export const authFlowUserEmailState = atom({
key: 'authFlowUserEmailState',
default: '',
default: process.env.NODE_ENV === 'development' ? 'tim@apple.dev' : '',
});

View File

@ -30,7 +30,9 @@ export function Index() {
const theme = useTheme();
useMockData();
const [, setAuthFlowUserEmail] = useRecoilState(authFlowUserEmailState);
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
authFlowUserEmailState,
);
useEffect(() => {
if (hasAccessToken()) {
@ -71,7 +73,7 @@ export function Index() {
</PrimaryButton>
<HorizontalSeparator />
<TextInput
value=""
value={authFlowUserEmail}
placeholder="Email"
onChange={(value) => setAuthFlowUserEmail(value)}
fullWidth={true}

View File

@ -29,13 +29,21 @@ const StyledButtonContainer = styled.div`
margin-top: ${({ theme }) => theme.spacing(7)};
`;
const StyledErrorContainer = styled.div`
color: ${({ theme }) => theme.red};
`;
export function PasswordLogin() {
const navigate = useNavigate();
const prefillPassword =
process.env.NODE_ENV === 'development' ? 'applecar2025' : '';
const [authFlowUserEmail, setAuthFlowUserEmail] = useRecoilState(
authFlowUserEmailState,
);
const [internalPassword, setInternalPassword] = useState('');
const [internalPassword, setInternalPassword] = useState(prefillPassword);
const [formError, setFormError] = useState('');
const userLogin = useCallback(async () => {
const response = await fetch(
@ -60,7 +68,10 @@ export function PasswordLogin() {
}
await getTokensFromLoginToken(loginToken.token);
navigate('/');
return;
}
const errorData = await response.json();
setFormError(errorData.message);
}, [authFlowUserEmail, internalPassword, navigate]);
useHotkeys(
@ -107,6 +118,9 @@ export function PasswordLogin() {
</PrimaryButton>
</StyledButtonContainer>
</StyledInputContainer>
{formError && (
<StyledErrorContainer>{formError}</StyledErrorContainer>
)}
</StyledContentContainer>
</Modal>
</>

View File

@ -60,15 +60,15 @@ export class AuthService {
},
});
assert(user, "This user doens't exist", NotFoundException);
assert(user.passwordHash, 'Something wrong happened', ForbiddenException);
assert(user, "This user doesn't exist", NotFoundException);
assert(user.passwordHash, 'Incorrect login method', ForbiddenException);
const isValid = await compareHash(
challengeInput.password,
user.passwordHash,
);
assert(isValid, 'Something wrong happened', ForbiddenException);
assert(isValid, 'Wrong password', ForbiddenException);
return user;
}
@ -80,7 +80,7 @@ export class AuthService {
},
});
assert(data, "This user doens't exist", NotFoundException);
assert(data, "This user doesn't exist", NotFoundException);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { passwordHash: _, ...user } = data;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long