source: jobvista-frontend/src/redux/actions/authActions.js@ 28b3398

main
Last change on this file since 28b3398 was 19398ad, checked in by 223021 <daniel.ilievski.2@…>, 7 weeks ago

Implemented backend and frontend CRUD operations for job advertisements

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import axios from "../../axios/axiosInstance";
2import {SIGN_IN, SIGN_OUT, UPDATE_TOKEN} from "../actionTypes";
3
4export const AuthActions = {
5 signUpJobSeeker: (firstName, lastName, phoneNumber, email, password, callback) => {
6 return dispatch => {
7 axios.post("/auth/signup/job-seeker", {
8 email,
9 password,
10 firstName,
11 lastName,
12 phoneNumber
13 }).then(response => {
14 dispatch(AuthActions.signIn(email, password));
15 callback(true, response);
16 }).catch((error) => {
17 callback(false, error);
18 });
19 };
20 },
21 signUpRecruiter: (companyName, phoneNumber, email, password, callback) => {
22 return dispatch => {
23 axios.post("/auth/signup/recruiter", {
24 email,
25 password,
26 companyName,
27 companyDescription: "",
28 phoneNumber
29 }).then(response => {
30 dispatch(AuthActions.signIn(email, password));
31 callback(true, response);
32 }).catch((error) => {
33 callback(false, error);
34 });
35 };
36 },
37
38 signIn: (email, password, callback) => {
39 return dispatch => {
40 axios.post("/auth/signin", {
41 email, password
42 }).then(jwtResponse => {
43 const response = jwtResponse.data;
44 const token = response.token;
45 //const refreshToken = response.refreshToken;
46 const user = {
47 id: response.id,
48 email: response.email,
49 name: response.name,
50 role: response.role
51 };
52 dispatch({
53 type: SIGN_IN,
54 payload: {
55 token,
56 //refreshToken,
57 user
58 }
59 });
60 callback && callback(true);
61 }).catch((error) => {
62 callback && callback(false, error);
63 });
64 };
65 },
66 signOut: () => {
67 return dispatch => {
68 dispatch({
69 type: SIGN_OUT
70 });
71 }
72 },
73 updateToken: (token) => {
74 return dispatch => {
75 dispatch({
76 type: UPDATE_TOKEN,
77 payload: token
78 });
79 }
80 }
81};
82
Note: See TracBrowser for help on using the repository browser.