Changeset befb988 for jobvista-frontend/src/redux/reducers
- Timestamp:
- 06/17/24 21:59:14 (5 months ago)
- Branches:
- main
- Children:
- 08f82ec
- Parents:
- b248810
- Location:
- jobvista-frontend/src/redux/reducers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
jobvista-frontend/src/redux/reducers/authReducer.js
rb248810 rbefb988 3 3 import {isExpired} from "react-jwt"; 4 4 import {CURRENT_USER, SIGN_IN, SIGN_OUT, UPDATE_TOKEN} from "../actionTypes"; 5 import {jwtDecode} from "jwt-decode"; 5 6 6 7 const initialState = { … … 13 14 case SIGN_IN: 14 15 localStorage.setItem(AUTH_TOKEN, action.payload.token); 15 localStorage.setItem(CURRENT_USER, JSON.stringify(action.payload.user));16 //localStorage.setItem(CURRENT_USER, JSON.stringify(action.payload.user)); 16 17 return { 17 18 ...state, … … 21 22 case UPDATE_TOKEN: 22 23 let token = action.payload; 24 let decodedToken; 23 25 let currentUser = ""; 26 if(token !=null) { 27 try { 28 decodedToken = jwtDecode(token); 29 } catch (error) { 30 console.log("Failed to decode token: " + error) 31 } 32 } 33 24 34 if(!isExpired(token)) { 25 35 localStorage.setItem(AUTH_TOKEN, token); 26 currentUser = JSON.parse(localStorage.getItem(CURRENT_USER)); 36 currentUser = { 37 name: decodedToken.name, 38 role: decodedToken.role, 39 access: decodedToken.access, 40 id: decodedToken.id 41 }; 27 42 } else { 28 localStorage.removeItem(CURRENT_USER);43 //localStorage.removeItem(CURRENT_USER); 29 44 localStorage.removeItem(AUTH_TOKEN); 30 45 currentUser = ""; … … 37 52 }; 38 53 case SIGN_OUT: 39 localStorage.removeItem(CURRENT_USER);54 //localStorage.removeItem(CURRENT_USER); 40 55 localStorage.removeItem(AUTH_TOKEN); 41 56 return { -
jobvista-frontend/src/redux/reducers/jobAdvertisementReducer.js
rb248810 rbefb988 1 1 import { 2 2 ADD_JOB_ADVERTISEMENT, 3 CURRENT_USER, DELETE_JOB_ADVERTISEMENT, EDIT_JOB_ADVERTISEMENT, 3 CURRENT_USER, 4 DELETE_JOB_ADVERTISEMENT, 5 EDIT_JOB_ADVERTISEMENT, 4 6 FETCH_JOB_ADVERTISEMENTS, 5 FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER, FILTER_JOB_ADVERTISEMENTS, FILTER_JOB_ADVERTISEMENTS_BY_RECRUITER 7 FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER, 8 FILTER_JOB_ADVERTISEMENTS, 9 FILTER_JOB_ADVERTISEMENTS_BY_RECRUITER, 10 SET_LOGO_URL 6 11 } from "../actionTypes"; 7 12 import {sortElementsBy} from "../../utils/utils";
Note:
See TracChangeset
for help on using the changeset viewer.