First part of httpOnly JWT cookie implementation

This commit is contained in:
Florian Sylvain
2023-01-12 00:04:26 +01:00
parent a09ae668ce
commit 200efe0e90
4 changed files with 43 additions and 20 deletions
+3 -3
View File
@@ -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 => {
+7 -6
View File
@@ -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