chore: add prettier frontent linter
This commit is contained in:
73 files changed
+18898
-4499
No files matched your search
+43
-43
@@ -1,88 +1,88 @@
|
||||
import store from '@/store'
|
||||
import router from '@/router'
|
||||
import { Base64 } from 'js-base64'
|
||||
import { baseURL } from '@/utils/constants'
|
||||
import store from "@/store";
|
||||
import router from "@/router";
|
||||
import { Base64 } from "js-base64";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
|
||||
export function parseToken (token) {
|
||||
const parts = token.split('.')
|
||||
export function parseToken(token) {
|
||||
const parts = token.split(".");
|
||||
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('token malformed')
|
||||
throw new Error("token malformed");
|
||||
}
|
||||
|
||||
const data = JSON.parse(Base64.decode(parts[1]))
|
||||
const data = JSON.parse(Base64.decode(parts[1]));
|
||||
|
||||
localStorage.setItem('jwt', token)
|
||||
store.commit('setJWT', token)
|
||||
store.commit('setUser', data.user)
|
||||
localStorage.setItem("jwt", token);
|
||||
store.commit("setJWT", token);
|
||||
store.commit("setUser", data.user);
|
||||
}
|
||||
|
||||
export async function validateLogin () {
|
||||
export async function validateLogin() {
|
||||
try {
|
||||
if (localStorage.getItem('jwt')) {
|
||||
await renew(localStorage.getItem('jwt'))
|
||||
if (localStorage.getItem("jwt")) {
|
||||
await renew(localStorage.getItem("jwt"));
|
||||
}
|
||||
} catch (_) {
|
||||
console.warn('Invalid JWT token in storage') // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
export async function login (username, password, recaptcha) {
|
||||
const data = { username, password, recaptcha }
|
||||
export async function login(username, password, recaptcha) {
|
||||
const data = { username, password, recaptcha };
|
||||
|
||||
const res = await fetch(`${baseURL}/api/login`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
const body = await res.text()
|
||||
const body = await res.text();
|
||||
|
||||
if (res.status === 200) {
|
||||
parseToken(body)
|
||||
parseToken(body);
|
||||
} else {
|
||||
throw new Error(body)
|
||||
throw new Error(body);
|
||||
}
|
||||
}
|
||||
|
||||
export async function renew (jwt) {
|
||||
export async function renew(jwt) {
|
||||
const res = await fetch(`${baseURL}/api/renew`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'X-Auth': jwt,
|
||||
}
|
||||
})
|
||||
"X-Auth": jwt,
|
||||
},
|
||||
});
|
||||
|
||||
const body = await res.text()
|
||||
const body = await res.text();
|
||||
|
||||
if (res.status === 200) {
|
||||
parseToken(body)
|
||||
parseToken(body);
|
||||
} else {
|
||||
throw new Error(body)
|
||||
throw new Error(body);
|
||||
}
|
||||
}
|
||||
|
||||
export async function signup (username, password) {
|
||||
const data = { username, password }
|
||||
export async function signup(username, password) {
|
||||
const data = { username, password };
|
||||
|
||||
const res = await fetch(`${baseURL}/api/signup`, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error(res.status)
|
||||
throw new Error(res.status);
|
||||
}
|
||||
}
|
||||
|
||||
export function logout () {
|
||||
store.commit('setJWT', '')
|
||||
store.commit('setUser', null)
|
||||
localStorage.setItem('jwt', null)
|
||||
router.push({path: '/login'})
|
||||
export function logout() {
|
||||
store.commit("setJWT", "");
|
||||
store.commit("setUser", null);
|
||||
localStorage.setItem("jwt", null);
|
||||
router.push({ path: "/login" });
|
||||
}
|
||||
Reference in new issue
Block a user