Skip to content

Commit

Permalink
Add types to login thing
Browse files Browse the repository at this point in the history
  • Loading branch information
arctixdev committed Feb 28, 2024
1 parent bdf1bf3 commit a7a471d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/authStore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import type { Writable } from 'svelte/store';
import { writable } from 'svelte/store';

export const userInfo = writable({});
export interface UserInfo {
email: string;
name: string;
username: string;
sub: string;
email_verified: boolean;
preferred_username: string;
given_name: string;
family_name: string;
}

export const userInfo: Writable<UserInfo> = writable();
11 changes: 3 additions & 8 deletions src/routes/signin/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import Keycloak from 'keycloak-js';
import { userInfo } from '../../authStore';
import { userInfo, type UserInfo } from '../../authStore';
const keycloak = new Keycloak({
url: 'http://localhost:8080/',
Expand All @@ -13,21 +13,16 @@
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);
userInfo.set(userInfoKc as UserInfo);
console.log('User info:', userInfoKc);
});
}
}).catch((e) => {
console.error(e);
});
console.log('loggedIn', loggedIn);
</script>

<svelte:head>
Expand Down

0 comments on commit a7a471d

Please sign in to comment.