-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
AdminMainPre.svelte
76 lines (67 loc) · 2.19 KB
/
AdminMainPre.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<script>
import {onMount} from "svelte";
import {checkAdminAccess, getSessionInfo} from "../../utils/dataFetching.js";
import {redirectToLogin} from "../../utils/helpers.js";
import BrowserCheck from "../BrowserCheck.svelte";
import Loading from "$lib/Loading.svelte";
import Button from "$lib/Button.svelte";
import AdminMain from "./AdminMain.svelte";
export let selected = 'Users';
let sessionInfo;
let isAdmin = false;
let mfaReqErr = false;
onMount(async () => {
let res = await getSessionInfo();
if (res.ok) {
let body = await res.json();
let resAdmin = await checkAdminAccess();
if (resAdmin.ok) {
sessionInfo = body;
isAdmin = true;
} else {
mfaReqErr = true;
sessionInfo = {};
}
} else {
redirectToLogin();
}
});
</script>
<svelte:head>
<title>Admin</title>
</svelte:head>
<BrowserCheck>
{#if !sessionInfo && !mfaReqErr}
<Loading/>
{:else if mfaReqErr}
<div class="noAdmin">
<div class="text">
A rauthy admin account must have <b>MFA enabled.</b><br>
Please navigate to your <b>account</b> and activate MFA.<br>
Afterwards, you need to do a logout and log back in.
</div>
<Button on:click={() => window.location.href = '/auth/v1/account'}>ACCOUNT</Button>
<!-- <Button on:click={() => window.location.href = '/auth/v1/account.html'}>ACCOUNT</Button>-->
</div>
{:else if !isAdmin}
<div class="noAdmin">
<div class="text">
You are not assigned to the <b>rauthy_admin</b> role and have no access to the admin panel.
</div>
<Button on:click={() => window.location.href = '/auth/v1/'}>GO BACK</Button>
</div>
{:else}
<AdminMain bind:sessionInfo bind:selected/>
{/if}
</BrowserCheck>
<style>
.noAdmin {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.text {
margin: 10px;
}
</style>