mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
First part of httpOnly JWT cookie implementation
This commit is contained in:
@@ -15,8 +15,8 @@ const baseURL = `http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PO
|
||||
|
||||
export async function getArticles(id: string) : Promise<Array<Article>> {
|
||||
return await fetch(`${baseURL}/articles/${id}`, {
|
||||
credentials: 'include',
|
||||
method: 'GET',
|
||||
headers: { "Authorization": `Bearer ${useAuthStore().token}` }
|
||||
})
|
||||
.then(result => result.json())
|
||||
.catch(error => {
|
||||
@@ -26,9 +26,9 @@ export async function getArticles(id: string) : Promise<Array<Article>> {
|
||||
|
||||
export async function postArticle(article: Article) : Promise<object> {
|
||||
return await fetch(`${baseURL}/articles/${article.titleID}`, {
|
||||
credentials: 'include',
|
||||
method: 'POST',
|
||||
headers: { "Authorization": `Bearer ${useAuthStore().token}` },
|
||||
body: JSON.stringify(article)
|
||||
body: JSON.stringify(article)
|
||||
})
|
||||
.then(result => result.json())
|
||||
.catch(error => {
|
||||
|
||||
@@ -19,11 +19,11 @@ function updateJWTcookies(JWTdata: jwtFormat): void {
|
||||
const cookieExpire = new Date(JWTdata.expire)
|
||||
cookieExpire.setDate(cookieExpire.getDate() + 1)
|
||||
|
||||
setCookie({
|
||||
key: 'JWTtoken',
|
||||
value: JWTdata.token,
|
||||
expire: cookieExpire.toString()
|
||||
})
|
||||
// setCookie({
|
||||
// key: 'JWTtoken',
|
||||
// value: JWTdata.token,
|
||||
// expire: cookieExpire.toString()
|
||||
// })
|
||||
setCookie({
|
||||
key: 'JWTexpire',
|
||||
value: JWTdata.expire,
|
||||
@@ -43,7 +43,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
|
||||
}
|
||||
updateJWTcookies(apiResponse)
|
||||
disableErrors()
|
||||
authStore.token = apiResponse.token
|
||||
authStore.token = 'pouet'
|
||||
authStore.expire = apiResponse.expire
|
||||
isTokenOK.value = true
|
||||
}
|
||||
@@ -51,6 +51,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
|
||||
function login(email: string, password: string): void {
|
||||
fetch(`http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}/login/`, {
|
||||
method: "POST",
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
email: email,
|
||||
password: password
|
||||
|
||||
Reference in New Issue
Block a user