UserRepo fixed oda so

This commit is contained in:
s-prechtl 2022-10-11 09:32:14 +02:00
parent d66b9272b7
commit 2d193969f7
3 changed files with 6 additions and 19 deletions

View file

@ -12,7 +12,7 @@ export class StrapiUserRepo implements UserRepository {
this.instance = new StrapiUserRepo(); this.instance = new StrapiUserRepo();
this.instance.setup().then(() => { this.instance.setup().then(() => {
if (!this.instance.currentUser?.jwt) { if (!this.instance.currentUser?.jwt) {
window.location.href = "/login"; //window.location.href = "/login";
} }
}); });
} }
@ -26,7 +26,7 @@ export class StrapiUserRepo implements UserRepository {
private static api: string = "http://localhost:1337/api" private static api: string = "http://localhost:1337/api"
private static apiUserEndpoint: string = StrapiUserRepo.api + "/local/auth" private static apiUserEndpoint: string = StrapiUserRepo.api + "/auth/local"
/** /**
* Sets the current user. * Sets the current user.
@ -66,7 +66,7 @@ export class StrapiUserRepo implements UserRepository {
}; };
if (authorization){ if (authorization){
requestInit["headers"] = { requestInit["headers"] = {
authorization: StrapiNoteRepository.getAuthorizationHeader(), authorization: StrapiNoteRepository.getAuthorizationHeader() ?? '',
} }
} }
if (body) { if (body) {

View file

@ -1,20 +1,6 @@
import {bearerFetch, jwt} from "../models/PomeloUtils"; import {StrapiUserRepo} from "../models/repos/user/StrapiUserRepo";
/** @type {import('./$types').PageLoad} */ /** @type {import('./$types').PageLoad} */
export async function load() { export async function load() {
let invalid = !jwt; // StrapiUserRepo.getInstance();
if (!invalid) {
const request = await bearerFetch("/users/me", jwt);
const response = await request.json();
invalid = "error" in response;
}
if (invalid) {
if (typeof window !== 'undefined') {
// @ts-ignore
window.location = "/login";
}
}
} }

View file

@ -74,6 +74,7 @@
<style> <style>
@import "src";
html, html,
body { body {
height: 100%; height: 100%;