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

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

Added no access page for new recruiters and admin panel for granting access

  • 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 access: response.hasAccess,
52 };
53 dispatch({
54 type: SIGN_IN,
55 payload: {
56 token,
57 //refreshToken,
58 user
59 }
60 });
61 callback && callback(true);
62 }).catch((error) => {
63 callback && callback(false, error);
64 });
65 };
66 },
67 signOut: () => {
68 return dispatch => {
69 dispatch({
70 type: SIGN_OUT
71 });
72 }
73 },
74 updateToken: (token) => {
75 return dispatch => {
76 dispatch({
77 type: UPDATE_TOKEN,
78 payload: token
79 });
80 }
81 }
82};
83
Note: See TracBrowser for help on using the repository browser.