Skip to content
Snippets Groups Projects
Unverified Commit 97cfe29e authored by Phoomparin Mano's avatar Phoomparin Mano Committed by GitHub
Browse files

feat(sdk): add useMetabaseAuthStatus hook to get current authentication status (#45606)

* add authentication status hook

* update docs
parent b5fa28e2
Branches
Tags
No related merge requests found
......@@ -843,6 +843,25 @@ return (
);
```
### Getting Metabase authentication status
You can query the Metabase authentication status using the `useMetabaseAuthStatus` hook.
This is useful if you want to completely hide Metabase components when the user is not authenticated.
This hook can only be used within components wrapped by `MetabaseProvider`.
```jsx
const auth = useMetabaseAuthStatus()
if (auth.status === "error") {
return <div>Failed to authenticate: {auth.error.message}</div>
}
if (auth.status === "success") {
return <InteractiveQuestion questionId={110} />;
}
```
### Reloading Metabase components
In case you need to reload a Metabase component, for example, your users modify your application data and that data is used to render a question in Metabase. If you embed this question and want to force Metabase to reload the question to show the latest data, you can do so by using the `key` prop to force a component to reload.
......
......@@ -2,3 +2,4 @@ export * from "./use-current-user";
export * from "./use-application-name";
export * from "./use-question-search";
export * from "./use-available-fonts";
export * from "./use-metabase-auth-status";
import { useSdkSelector } from "embedding-sdk/store";
import { getLoginStatus } from "embedding-sdk/store/selectors";
export const useMetabaseAuthStatus = () => useSdkSelector(getLoginStatus);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment