Skip to content

Commit

Permalink
Acquire and set JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpgreen2 committed Sep 8, 2023
1 parent 770d813 commit e136526
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion web-admin/src/routes/[organization]/[project]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { goto } from "$app/navigation";
import { page } from "$app/stores";
import RuntimeProvider from "@rilldata/web-common/runtime-client/RuntimeProvider.svelte";
import { createAdminServiceGetDeploymentCredentials } from "../../../client";
import { viewAsUserStore } from "../../../components/authentication/viewAsUserStore";
import { useProjectRuntime } from "../../../components/projects/selectors";
$: projRuntime = useProjectRuntime(
Expand All @@ -15,13 +17,27 @@
// Redirect any nested routes (notably dashboards) to the project page
goto(`/${$page.params.organization}/${$page.params.project}`);
}
// if viewAs is set (which only admins can configure), we need to update the runtime with the new jwt
$: deploymentCredsQuery = createAdminServiceGetDeploymentCredentials(
$page.params.organization,
$page.params.project,
{
userId: $viewAsUserStore?.id,
},
{
query: {
enabled: $viewAsUserStore?.id !== undefined,
},
}
);
</script>

{#if $projRuntime.data}
<RuntimeProvider
host={$projRuntime.data.host}
instanceId={$projRuntime.data.instanceId}
jwt={$projRuntime.data?.jwt}
jwt={$deploymentCredsQuery.data?.jwt || $projRuntime.data?.jwt}
>
<slot />
</RuntimeProvider>
Expand Down

0 comments on commit e136526

Please sign in to comment.