Skip to content

Commit

Permalink
Add basic login
Browse files Browse the repository at this point in the history
  • Loading branch information
arctixdev committed Feb 28, 2024
1 parent 9b93de9 commit bdf1bf3
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 101 deletions.
Binary file modified bun.lockb
Binary file not shown.
174 changes: 87 additions & 87 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
{
"name": "frontend",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@fontsource/fira-mono": "^5.0.8",
"@neoconfetti/svelte": "^2.2.1",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.2",
"@types/cookie": "^0.6.0",
"@types/node": "^20.11.20",
"@types/web": "^0.0.140",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"mdi-svelte": "^1.1.2",
"postcss": "^8.4.35",
"postcss-load-config": "^5.0.3",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.1",
"prettier-plugin-tailwindcss": "^0.5.11",
"sass": "^1.71.1",
"svelte": "^4.2.12",
"svelte-check": "^3.6.4",
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^5.1.4"
},
"type": "module",
"dependencies": {
"@hocuspocus/provider": "^2.11.2",
"@internationalized/date": "^3.5.2",
"@mdi/js": "^7.4.47",
"@tiptap-pro/extension-mathematics": "^2.7.5",
"@tiptap/core": "^2.2.4",
"@tiptap/extension-blockquote": "^2.2.4",
"@tiptap/extension-bold": "^2.2.4",
"@tiptap/extension-bullet-list": "^2.2.4",
"@tiptap/extension-code": "^2.2.4",
"@tiptap/extension-code-block": "^2.2.4",
"@tiptap/extension-collaboration": "^2.2.4",
"@tiptap/extension-collaboration-cursor": "^2.2.4",
"@tiptap/extension-color": "^2.2.4",
"@tiptap/extension-document": "^2.2.4",
"@tiptap/extension-dropcursor": "^2.2.4",
"@tiptap/extension-gapcursor": "^2.2.4",
"@tiptap/extension-hard-break": "^2.2.4",
"@tiptap/extension-heading": "^2.2.4",
"@tiptap/extension-horizontal-rule": "^2.2.4",
"@tiptap/extension-image": "^2.2.4",
"@tiptap/extension-italic": "^2.2.4",
"@tiptap/extension-list-item": "^2.2.4",
"@tiptap/extension-ordered-list": "^2.2.4",
"@tiptap/extension-paragraph": "^2.2.4",
"@tiptap/extension-placeholder": "^2.2.4",
"@tiptap/extension-strike": "^2.2.4",
"@tiptap/extension-subscript": "^2.2.4",
"@tiptap/extension-superscript": "^2.2.4",
"@tiptap/extension-task-item": "^2.2.4",
"@tiptap/extension-task-list": "^2.2.4",
"@tiptap/extension-text": "^2.2.4",
"@tiptap/extension-text-style": "^2.2.4",
"@tiptap/pm": "^2.2.4",
"akademia-authorizer-svelte": "^0.1.12",
"bits-ui": "^0.18.2",
"clsx": "^2.1.0",
"cmdk-sv": "^0.0.13",
"katex": "^0.16.9",
"lucide-svelte": "^0.334.0",
"mathlive": "^0.98.6",
"svelte-tiptap": "^1.1.2",
"tailwind-merge": "^2.2.1",
"tailwind-variants": "^0.2.0",
"tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1",
"yjs": "^13.6.12"
}
"name": "frontend",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
"devDependencies": {
"@fontsource/fira-mono": "^5.0.8",
"@neoconfetti/svelte": "^2.2.1",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.2",
"@types/cookie": "^0.6.0",
"@types/node": "^20.11.20",
"@types/web": "^0.0.140",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"autoprefixer": "^10.4.17",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"mdi-svelte": "^1.1.2",
"postcss": "^8.4.35",
"postcss-load-config": "^5.0.3",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.1",
"prettier-plugin-tailwindcss": "^0.5.11",
"sass": "^1.71.1",
"svelte": "^4.2.12",
"svelte-check": "^3.6.4",
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^5.1.4"
},
"type": "module",
"dependencies": {
"@hocuspocus/provider": "^2.11.2",
"@internationalized/date": "^3.5.2",
"@mdi/js": "^7.4.47",
"@tiptap-pro/extension-mathematics": "^2.7.5",
"@tiptap/core": "^2.2.4",
"@tiptap/extension-blockquote": "^2.2.4",
"@tiptap/extension-bold": "^2.2.4",
"@tiptap/extension-bullet-list": "^2.2.4",
"@tiptap/extension-code": "^2.2.4",
"@tiptap/extension-code-block": "^2.2.4",
"@tiptap/extension-collaboration": "^2.2.4",
"@tiptap/extension-collaboration-cursor": "^2.2.4",
"@tiptap/extension-color": "^2.2.4",
"@tiptap/extension-document": "^2.2.4",
"@tiptap/extension-dropcursor": "^2.2.4",
"@tiptap/extension-gapcursor": "^2.2.4",
"@tiptap/extension-hard-break": "^2.2.4",
"@tiptap/extension-heading": "^2.2.4",
"@tiptap/extension-horizontal-rule": "^2.2.4",
"@tiptap/extension-image": "^2.2.4",
"@tiptap/extension-italic": "^2.2.4",
"@tiptap/extension-list-item": "^2.2.4",
"@tiptap/extension-ordered-list": "^2.2.4",
"@tiptap/extension-paragraph": "^2.2.4",
"@tiptap/extension-placeholder": "^2.2.4",
"@tiptap/extension-strike": "^2.2.4",
"@tiptap/extension-subscript": "^2.2.4",
"@tiptap/extension-superscript": "^2.2.4",
"@tiptap/extension-task-item": "^2.2.4",
"@tiptap/extension-task-list": "^2.2.4",
"@tiptap/extension-text": "^2.2.4",
"@tiptap/extension-text-style": "^2.2.4",
"@tiptap/pm": "^2.2.4",
"bits-ui": "^0.18.2",
"clsx": "^2.1.0",
"cmdk-sv": "^0.0.13",
"katex": "^0.16.9",
"keycloak-js": "^23.0.7",
"lucide-svelte": "^0.334.0",
"mathlive": "^0.98.6",
"svelte-tiptap": "^1.1.2",
"tailwind-merge": "^2.2.1",
"tailwind-variants": "^0.2.0",
"tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1",
"yjs": "^13.6.12"
}
}
3 changes: 3 additions & 0 deletions src/authStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { writable } from 'svelte/store';

export const userInfo = writable({});
46 changes: 32 additions & 14 deletions src/routes/signin/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<script lang="ts">
import { getContext } from 'svelte';
import { Authorizer } from 'akademia-authorizer-svelte';
import { goto } from '$app/navigation';
import type { Readable } from 'svelte/store';
import type { AuthorizerState } from 'akademia-authorizer-svelte/types';
import Keycloak from 'keycloak-js';
import { userInfo } from '../../authStore';
let state: AuthorizerState;
const store = <Readable<AuthorizerState>>getContext('authorizerContext');
const keycloak = new Keycloak({
url: 'http://localhost:8080/',
realm: 'akademia',
clientId: 'akademia-frontend',
});
let loggedIn = false;
store.subscribe((data: AuthorizerState) => {
state = data;
if (state.token) {
goto('/workspace/home');
keycloak.init({
onLoad: 'login-required',
}).then((authenticated) => {
console.log("tyest")
loggedIn = authenticated;
if (loggedIn) {
console.log('authenticated', authenticated);
loggedIn = true;
keycloak.loadUserInfo().then((userInfoKc) => {
userInfo.set(userInfoKc);
});
}
}).catch((e) => {
console.error(e);
});
console.log('loggedIn', loggedIn);
</script>

<svelte:head>
Expand All @@ -24,9 +38,13 @@
<div class="login-cont">
<img src="/favicon.png" class="logo" alt="Akademia logo" />
<h1 class="header">Velkommen til Akademia!</h1>
<h2>Vælg en loginmetode</h2>
<br />
<Authorizer />
{#if loggedIn}
<h2>Du er logget ind som {$userInfo.preferred_username}!</h2>
<button on:click={() => {keycloak.logout();}}>Log ud</button>
{:else}
Du er ikke logget ind
<button on:click={() => {keycloak.login();}}>Login</button>
{/if}
</div>
</div>

Expand Down

0 comments on commit bdf1bf3

Please sign in to comment.