[d8b6c91] | 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;
|
---|
[19398ad] | 45 | //const refreshToken = response.refreshToken;
|
---|
[d8b6c91] | 46 | const user = {
|
---|
| 47 | name: response.name,
|
---|
[b248810] | 48 | role: response.role,
|
---|
| 49 | access: response.hasAccess,
|
---|
[befb988] | 50 | id: response.id,
|
---|
[d8b6c91] | 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 |
|
---|