mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
refactor: Refactorisation du login et de admin/subscription
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
|
||||
import {
|
||||
BE_AUTH_LOGIN_URL,
|
||||
BE_AUTH_REGISTER_URL,
|
||||
BE_AUTH_PROFILE_URL,
|
||||
BE_AUTH_RESET_PASSWORD_URL,
|
||||
BE_AUTH_NEW_PASSWORD_URL,
|
||||
FE_USERS_LOGIN_URL ,
|
||||
} from '@/utils/Url';
|
||||
|
||||
@ -9,6 +12,21 @@ import {mockUser} from "@/data/mockUsersData";
|
||||
|
||||
const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true';
|
||||
|
||||
export const login = (data, csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_LOGIN_URL}`,
|
||||
{
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
credentials: 'include',
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the user after confirming the action.
|
||||
@ -49,7 +67,6 @@ const request = new Request(
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
|
||||
export const updateProfile = (id, data, csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_PROFILE_URL}/${id}`,
|
||||
@ -64,4 +81,62 @@ export const updateProfile = (id, data, csrfToken) => {
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
export const sendNewPassword = (data, csrfToken) => {
|
||||
|
||||
const request = new Request(
|
||||
`${BE_AUTH_NEW_PASSWORD_URL}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
export const subscribe = (data,csrfToken) =>{
|
||||
const request = new Request(
|
||||
`${BE_AUTH_REGISTER_URL}`,
|
||||
{
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify( data),
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
export const resetPassword = (uuid, data, csrfToken) => {
|
||||
const request = new Request(
|
||||
`${BE_AUTH_RESET_PASSWORD_URL}/${uuid}`,
|
||||
{
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type':'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data),
|
||||
}
|
||||
);
|
||||
return fetch(request).then(response => response.json())
|
||||
}
|
||||
|
||||
export const getResetPassword = (uuid) => {
|
||||
const url= `${BE_AUTH_RESET_PASSWORD_URL}/${uuid}`;
|
||||
return fetch(url, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then(response => response.json())
|
||||
}
|
||||
Reference in New Issue
Block a user