get user by thunkApi instead of jwtDecode token
This commit is contained in:
1 parent
f2ae99768a
commit
e8c0a98a7b
4 files changed
+7
-11
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@@ -45,7 +44,7 @@ export const login = createAsyncThunk("auth/login", async (form, thunkApi) => {
|
|||||||
|
|
||||||
export const update = createAsyncThunk("auth/update", async (data, thunkApi) => {
|
export const update = createAsyncThunk("auth/update", async (data, thunkApi) => {
|
||||||
const { localData: form } = data;
|
const { localData: form } = data;
|
||||||
const user = jwtDecode(token);
|
const user = thunkApi.getState().auth.user;
|
||||||
try {
|
try {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
form.firstName && fd.append("firstName", form.firstName);
|
form.firstName && fd.append("firstName", form.firstName);
|
||||||
@@ -77,8 +76,8 @@ export const update = createAsyncThunk("auth/update", async (data, thunkApi) =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const deleteUser = createAsyncThunk("auth/delete", async (data, thunkApi) => {
|
export const deleteUser = createAsyncThunk("auth/delete", async (_, thunkApi) => {
|
||||||
const user = jwtDecode(data);
|
const user = thunkApi.getState().auth.user;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await networkService.deleteUser({ userId: user._id, });
|
const res = await networkService.deleteUser({ userId: user._id, });
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
|
||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -70,8 +69,8 @@ export const getInfrastructureMonitorById = createAsyncThunk(
|
|||||||
|
|
||||||
export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
|
export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
|
||||||
"infrastructureMonitors/getMonitorsByTeamId",
|
"infrastructureMonitors/getMonitorsByTeamId",
|
||||||
async (token, thunkApi) => {
|
async (_, thunkApi) => {
|
||||||
const user = jwtDecode(token);
|
const user = thunkApi.getState().auth.user;
|
||||||
try {
|
try {
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
|
||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -70,8 +69,8 @@ export const getPagespeedMonitorById = createAsyncThunk(
|
|||||||
|
|
||||||
export const getPageSpeedByTeamId = createAsyncThunk(
|
export const getPageSpeedByTeamId = createAsyncThunk(
|
||||||
"pageSpeedMonitors/getPageSpeedByTeamId",
|
"pageSpeedMonitors/getPageSpeedByTeamId",
|
||||||
async (token, thunkApi) => {
|
async (_, thunkApi) => {
|
||||||
const user = jwtDecode(token);
|
const user = thunkApi.getState().auth.user;
|
||||||
try {
|
try {
|
||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
import { jwtDecode } from "jwt-decode";
|
|
||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|||||||
Reference in new issue
Block a user