mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-13 17:27:37 -05:00
everything switched over, time to test
This commit is contained in:
@@ -22,11 +22,33 @@ export const authenticateUser = createAsyncThunk(
|
||||
|
||||
export const loginUser = createAsyncThunk(
|
||||
'user/login',
|
||||
async ({ getState }) => {
|
||||
async (data) => {
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/login"
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include"
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
|
||||
export const registerUser = createAsyncThunk(
|
||||
'user/register',
|
||||
async (data) => {
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/register"
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
@@ -36,6 +58,24 @@ export const loginUser = createAsyncThunk(
|
||||
|
||||
|
||||
|
||||
export const updateProfile = createAsyncThunk(
|
||||
'user/updateProfile',
|
||||
async (user) => {
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + user.userId;
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(user)
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
|
||||
export const logoutUser = createAsyncThunk(
|
||||
'user/logout',
|
||||
async ({ getState }) => {
|
||||
@@ -50,6 +90,63 @@ export const logoutUser = createAsyncThunk(
|
||||
}
|
||||
)
|
||||
|
||||
export const sendConfirmEmail = createAsyncThunk(
|
||||
'user/sendConfirmEmail',
|
||||
async (userId) => {
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + userId + "/send-confirm";
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
|
||||
export const resetPassword = createAsyncThunk(
|
||||
'user/resetPassword',
|
||||
async (data) => {
|
||||
const {userId, token, password} = data;
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + userId + "/confirm/" + token
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({password})
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
|
||||
export const sendResetPassword = createAsyncThunk(
|
||||
'user/sendResetPassword',
|
||||
async (data) => {
|
||||
const {userId, token, password} = data;
|
||||
const url = process.env.REACT_APP_ACCOUNT_SERVER + "/api/send-reset-password"
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}).then(
|
||||
(data) => data.json()
|
||||
)
|
||||
return res;
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
export const userSlice = createSlice({
|
||||
name: 'user',
|
||||
initialState: {
|
||||
@@ -59,7 +156,12 @@ export const userSlice = createSlice({
|
||||
userId: "",
|
||||
admin: false,
|
||||
email: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
location: "",
|
||||
screenName: ""
|
||||
},
|
||||
|
||||
reducers: {
|
||||
increment: (state) => {
|
||||
// Redux Toolkit allows us to write "mutating" logic in reducers. It
|
||||
@@ -70,6 +172,44 @@ export const userSlice = createSlice({
|
||||
},
|
||||
},
|
||||
extraReducers: {
|
||||
[loginUser.fulfilled]: (state, data) => {
|
||||
const {payload} = data;
|
||||
if (payload.success) {
|
||||
state.authenticated = true;
|
||||
state.hasAuthenticated = true;
|
||||
state.userId = payload.user.userId;
|
||||
state.admin = payload.user.admin;
|
||||
state.email = payload.user.email;
|
||||
state.firstName = payload.user.firstName;
|
||||
state.lastName = payload.user.lastName;
|
||||
state.location = payload.user.location;
|
||||
state.screenName = payload.user.screenName;
|
||||
} else {
|
||||
state.authenticated = false;
|
||||
state.hasAuthenticated = true;
|
||||
}
|
||||
},
|
||||
[updateProfile.fulfilled]: (state, data) => {
|
||||
const {payload} = data;
|
||||
if (payload.success) {
|
||||
state.authenticated = true;
|
||||
state.hasAuthenticated = true;
|
||||
state.userId = payload.user.userId;
|
||||
state.admin = payload.user.admin;
|
||||
state.email = payload.user.email;
|
||||
state.firstName = payload.user.firstName;
|
||||
state.lastName = payload.user.lastName;
|
||||
state.location = payload.user.location;
|
||||
state.screenName = payload.user.screenName;
|
||||
} else {
|
||||
state.authenticated = false;
|
||||
state.hasAuthenticated = true;
|
||||
}
|
||||
},
|
||||
[loginUser.rejected]: (state, { payload }) => {
|
||||
state.authenticated = false;
|
||||
state.hasAuthenticated = true;
|
||||
},
|
||||
[authenticateUser.fulfilled]: (state, data) => {
|
||||
const {payload} = data;
|
||||
if (payload.success) {
|
||||
@@ -78,6 +218,10 @@ export const userSlice = createSlice({
|
||||
state.userId = payload.user.userId;
|
||||
state.admin = payload.user.admin;
|
||||
state.email = payload.user.email;
|
||||
state.firstName = payload.user.firstName;
|
||||
state.lastName = payload.user.lastName;
|
||||
state.location = payload.user.location;
|
||||
state.screenName = payload.user.screenName;
|
||||
} else {
|
||||
state.authenticated = false;
|
||||
state.hasAuthenticated = true;
|
||||
|
||||
Reference in New Issue
Block a user