You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I can't get my code to work, maybe someone can give me some help?
What I want to do is call an API with the idToken/Bearer of the user... I can get the Bearer inside of the <SignedIn let:user> component, but not in the <script> section... What am I doing wrong?
working example
My app, auth, etc are stored in '$lib/firebase', it's 1:1 as in the example
<scriptlang="ts">
import { GoogleAuthProvider, signInWithPopup } from"firebase/auth";import { FirebaseApp, SignedIn, SignedOut } from'sveltefire';import { projects, crnt_project } from'$lib/docdata'; // simple writableasyncfunction loadProjects(bearertoken) {console.log("loading projects now form api")const response =awaitfetch('http://localhost:8001/projects', { method: 'GET', headers: {"accept" : "application/json", "Authorization": "Bearer "+bearertoken} });const json =awaitresponse.json();console.log("json response for projects: "+json)projects.set(json);returnjson; }let dataPromise;
</script>
<FirebaseApp {auth}>
<SignedInlet:userlet:signOut>
This is the only way how I got it to work:
{dataPromise=loadData(user.accessToken)}
{#awaitdataPromise}
<p>loading projects...</p>
{:thenprojects}
<form>
<selectbind:value={$crnt_project} class="form-control"name="project"id="project">
{#eachprojectsasproject} // would be nice btw to use $projects, but it's not set at this point ??
{#if$crnt_project===project.id}
<optionvalue={project.id} selected>{project.name}</option>
{:else}
<optionvalue={project.id}>{project.name}</option>
{/if}
{/each}
</select>
</form>
{/await}
</SignedIn>
</FirebaseApp>
what would I expect to be able to do?
<script>
onMount() -> load all the data for the user with his bearerToken
</script>
{#await all data }
please wait a moment...
{:then }
render all the stuff
{/await}
The text was updated successfully, but these errors were encountered:
can you try this after let dataPromise;
onMount(async () => {
const user = // get the user object or access it from props
dataPromise = loadProjects(user.accessToken);
});
you can import { onMount } from 'svelte';
Hi, I can't get my code to work, maybe someone can give me some help?
What I want to do is call an API with the idToken/Bearer of the user... I can get the Bearer inside of the
<SignedIn let:user>
component, but not in the <script> section... What am I doing wrong?working example
My app, auth, etc are stored in '$lib/firebase', it's 1:1 as in the example
what would I expect to be able to do?
The text was updated successfully, but these errors were encountered: