Skip to content

Commit

Permalink
Made modification to only allow auth with username
Browse files Browse the repository at this point in the history
  • Loading branch information
flemton committed Dec 17, 2023
1 parent ec3731c commit 826b15e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 48 deletions.
23 changes: 6 additions & 17 deletions src/components/Session/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { useDispatch, useSelector } from 'react-redux';
import { loginAsync } from '../../redux/slices/loginSlice';

const Login = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [username, setUsername] = useState('');
const navigate = useNavigate();
const dispatch = useDispatch();
const { data } = useSelector((state) => state.login);

const handleLogin = (e) => {
e.preventDefault();
dispatch(loginAsync(email, password));
dispatch(loginAsync(username));
};

useEffect(() => {
Expand All @@ -31,21 +30,11 @@ const Login = () => {
<h2 className="text-center mb-4">LogIn</h2>
<div className="mb-3">
<input
type="email"
type="name"
className="form-control"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<div className="mb-3">
<input
type="password"
className="form-control"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
/>
</div>
Expand Down
26 changes: 1 addition & 25 deletions src/components/Session/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ import { registerAsync } from '../../redux/slices/registerSlice';

const Register = () => {
const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const navigate = useNavigate();
const dispatch = useDispatch();
const data = useSelector((state) => state.register);

const handleSignUp = (e) => {
e.preventDefault();
dispatch(registerAsync({ username, email, password })).then((success) => {
dispatch(registerAsync({ username })).then((success) => {
if (success) {
navigate('/home');
}
});
};

useEffect(() => {
console.log(data);
if (data?.success) {
navigate('/home');
}
Expand All @@ -44,27 +41,6 @@ const Register = () => {
required
/>
</div>
<div className="mb-3">
<input
type="email"
className="form-control"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>

<div className="mb-3">
<input
type="password"
className="form-control"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
<div className="d-flex justify-content-between">
<button
className="border-1 btn m-2 rounded-circle btn-warning"
Expand Down
5 changes: 2 additions & 3 deletions src/redux/slices/loginSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const loginSlice = createSlice({

export const { fetchDataStart, fetchDataSuccess, fetchDataFailure } = loginSlice.actions;

export const loginAsync = (email, password) => async (dispatch) => {
export const loginAsync = (username) => async (dispatch) => {
dispatch(fetchDataStart());
try {
const response = await fetch(`${apiUrl}login`, {
Expand All @@ -36,8 +36,7 @@ export const loginAsync = (email, password) => async (dispatch) => {
},
body: JSON.stringify({
user: {
email,
password,
username,
},
}),
credentials: 'include',
Expand Down
4 changes: 1 addition & 3 deletions src/redux/slices/registerSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import apiUrl from '../../misc/apiUrl';

export const registerAsync = createAsyncThunk(
'register/registerAsync',
async ({ username, email, password }) => {
async ({ username }) => {
const response = await fetch(`${apiUrl}users`, {
method: 'POST',
headers: {
Expand All @@ -12,8 +12,6 @@ export const registerAsync = createAsyncThunk(
body: JSON.stringify({
user: {
username,
email,
password,
},
}),
});
Expand Down

0 comments on commit 826b15e

Please sign in to comment.