Using Typescript in SvelteKit, I have an .ts file located in the $lib folder.
Attempting to access the user/session from '$app/stores'
within the .ts file results in the following code snippet:
import { get } from 'svelte/store';
import { session } from "$app/stores";
function getUser(){
const {user} = get(session);
console.log(user);
}
However, upon calling the function, an error message is displayed in the console:
Uncaught (in promise) Error: Function called outside component initialization
Any suggestions on how to resolve this issue would be greatly appreciated!
Thank you in advance!