From 546d1677c3dfd53234c5a300487289d54871d20d Mon Sep 17 00:00:00 2001 From: Taras Date: Mon, 24 Jul 2023 12:56:36 -0700 Subject: [PATCH] Add signout logic --- packages/app/src/App.tsx | 61 ++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index fb4e2fd102..ab32eb4021 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -41,24 +41,52 @@ import { GraphiQLPage } from '@backstage/plugin-graphiql'; import { SignInPage } from '@backstage/core-components'; import { auth0AuthApiRef } from './internal'; import Star from '@material-ui/icons/Star'; -import { githubAuthApiRef } from '@backstage/core-plugin-api'; +import { + IdentityApi, + githubAuthApiRef, + storageApiRef, + useApi, +} from '@backstage/core-plugin-api'; import { SecretsContextProvider } from '@backstage/plugin-scaffolder-react'; const app = createApp({ apis, components: { - SignInPage: props => ( - - ), + SignInPage: props => { + const storage = useApi(storageApiRef); + return ( + { + props.onSignInSuccess({ + getProfileInfo() { + return identityApi.getProfileInfo(); + }, + getBackstageIdentity() { + return identityApi.getBackstageIdentity(); + }, + getCredentials() { + return identityApi.getCredentials(); + }, + async signOut() { + await identityApi.signOut(); + // happens after signout + storage.remove('authenticated/user'); + }, + }); + // happens after successful authentication + const identity = await identityApi.getBackstageIdentity(); + storage.set('authenticated/user', identity.userEntityRef); + }} + auto + provider={{ + id: 'auth0-auth-provider', + title: 'Auth0', + message: 'Sign in using Auth0', + apiRef: auth0AuthApiRef, + }} + /> + ); + }, }, bindRoutes({ bind }) { bind(catalogPlugin.externalRoutes, { @@ -98,7 +126,10 @@ const routes = ( - } /> + } + /> } /> {routes} - + , );