Set auth token when logging in
This commit is contained in:
parent
0f1b10d2d7
commit
02bfbabcfc
@ -10,10 +10,16 @@ document.getElementById("loginForm").addEventListener("submit", function(event)
|
|||||||
|
|
||||||
login(emailOrUsername, password)
|
login(emailOrUsername, password)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
document.cookie = `auth-token=${response.token}`;
|
||||||
|
|
||||||
|
localStorage.setItem("user", {
|
||||||
|
id: response.id,
|
||||||
|
username: response.userName,
|
||||||
|
});
|
||||||
|
|
||||||
location.href = "/home";
|
location.href = "/home";
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
|
||||||
document.getElementById("form-error").innerText = error;
|
document.getElementById("form-error").innerText = error;
|
||||||
document.getElementById("form-error").style.display = "block";
|
document.getElementById("form-error").style.display = "block";
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { address } from "./constants.js";
|
import { address } from "./constants.js";
|
||||||
|
|
||||||
export async function request(method, path, body = null) {
|
export async function request(method, path, body = null) {
|
||||||
const token = document.cookie.match(/\bauth-token=(\S+)/);
|
const token = document.cookie.match(/\bauth-token=([^;\s]+)/);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(address + path, {
|
fetch(address + path, {
|
||||||
|
Loading…
Reference in New Issue
Block a user