Skip to content

Commit

Permalink
Merge pull request #53 from AnWhiteM/login-page
Browse files Browse the repository at this point in the history
autologin logic
  • Loading branch information
AnWhiteM authored Jun 13, 2024
2 parents 97ffb61 + 714b013 commit 6cf1869
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/components/RegistrationForm/RegistrationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export const RegistrationForm = () => {
const dispatch = useDispatch();
const navigate = useNavigate();

const handleSubmit = (values, actions) => {
console.log(values);
dispatch(register(values));
toast.success("Ти зареєструвався");
const handleSubmit = async (values, actions) => {
await dispatch(register(values)).unwrap();
toast.success("Registered successfully");
navigate("/home");
actions.resetForm();
};
Expand Down
5 changes: 4 additions & 1 deletion src/redux/auth/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const register = createAsyncThunk(
try {
axios.defaults.headers.secretkey = "QWERTY";
await axios.post("/auth/register", userInfo);
const logResponse = await axios.post("/auth/login", userInfo);
const logResponse = await axios.post("/auth/login", {
email: userInfo.email,
password: userInfo.password,
});
setAuthHeader(logResponse.data.token);
return logResponse.data;
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions src/redux/auth/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const authSlice = createSlice({
.addCase(register.fulfilled, (state, action) => {
state.user = action.payload.user;
state.token = action.payload.token;
state.isLoggedIn = true;
})
.addCase(register.rejected, (state) => {
state.loading = false;
Expand Down

0 comments on commit 6cf1869

Please sign in to comment.