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)
|
||||
.then(response => {
|
||||
document.cookie = `auth-token=${response.token}`;
|
||||
|
||||
localStorage.setItem("user", {
|
||||
id: response.id,
|
||||
username: response.userName,
|
||||
});
|
||||
|
||||
location.href = "/home";
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
document.getElementById("form-error").innerText = error;
|
||||
document.getElementById("form-error").style.display = "block";
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { address } from "./constants.js";
|
||||
|
||||
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) => {
|
||||
fetch(address + path, {
|
||||
|
Loading…
Reference in New Issue
Block a user