1 | import axios from "../../axios/axiosInstance";
|
---|
2 | import {SIGN_IN, SIGN_OUT, UPDATE_TOKEN} from "../actionTypes";
|
---|
3 |
|
---|
4 | export 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; // Corrected typo
|
---|
46 | const user = {
|
---|
47 | email: response.email,
|
---|
48 | name: response.name,
|
---|
49 | role: response.role
|
---|
50 | };
|
---|
51 | dispatch({
|
---|
52 | type: SIGN_IN,
|
---|
53 | payload: {
|
---|
54 | token,
|
---|
55 | //refreshToken,
|
---|
56 | user
|
---|
57 | }
|
---|
58 | });
|
---|
59 | callback && callback(true);
|
---|
60 | }).catch((error) => {
|
---|
61 | callback && callback(false, error);
|
---|
62 | });
|
---|
63 | };
|
---|
64 | },
|
---|
65 | signOut: () => {
|
---|
66 | return dispatch => {
|
---|
67 | dispatch({
|
---|
68 | type: SIGN_OUT
|
---|
69 | });
|
---|
70 | }
|
---|
71 | },
|
---|
72 | updateToken: (token) => {
|
---|
73 | return dispatch => {
|
---|
74 | dispatch({
|
---|
75 | type: UPDATE_TOKEN,
|
---|
76 | payload: token
|
---|
77 | });
|
---|
78 | }
|
---|
79 | }
|
---|
80 | };
|
---|
81 |
|
---|