source: jobvista-frontend/src/redux/actions/authActions.js@ 4d97b63

main
Last change on this file since 4d97b63 was 4d97b63, checked in by 223021 <daniel.ilievski.2@…>, 3 months ago

Implemented Google login, additional file uploads, response messages and email notifications

  • Property mode set to 100644
File size: 3.3 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 signInGoogle: (tokenId, callback) => {
39 return dispatch => {
40 axios.post("/auth/google", { tokenId })
41 .then(jwtResponse => {
42 const response = jwtResponse.data;
43 const token = response.token;
44 const user = {
45 name: response.name,
46 role: response.role,
47 access: response.hasAccess,
48 id: response.id,
49 };
50 dispatch({
51 type: SIGN_IN,
52 payload: {
53 token,
54 user
55 }
56 });
57 callback && callback(true);
58 }).catch(error => {
59 callback && callback(false, error);
60 });
61 };
62 },
63
64 signIn: (email, password, callback) => {
65 return dispatch => {
66 axios.post("/auth/signin", {
67 email, password
68 }).then(jwtResponse => {
69 const response = jwtResponse.data;
70 const token = response.token;
71 //const refreshToken = response.refreshToken;
72 const user = {
73 name: response.name,
74 role: response.role,
75 access: response.hasAccess,
76 id: response.id,
77 };
78 dispatch({
79 type: SIGN_IN,
80 payload: {
81 token,
82 //refreshToken,
83 user
84 }
85 });
86 callback && callback(true);
87 }).catch((error) => {
88 callback && callback(false, error);
89 });
90 };
91 },
92 signOut: () => {
93 return dispatch => {
94 dispatch({
95 type: SIGN_OUT
96 });
97 }
98 },
99 updateToken: (token) => {
100 return dispatch => {
101 dispatch({
102 type: UPDATE_TOKEN,
103 payload: token
104 });
105 }
106 }
107};
108
Note: See TracBrowser for help on using the repository browser.