+
)
diff --git a/frontend/src/toolbar/flags/flagsToolbarLogic.ts b/frontend/src/toolbar/flags/flagsToolbarLogic.ts
index 60c1f568f45a6..e1f41cabca73c 100644
--- a/frontend/src/toolbar/flags/flagsToolbarLogic.ts
+++ b/frontend/src/toolbar/flags/flagsToolbarLogic.ts
@@ -40,11 +40,6 @@ export const flagsToolbarLogic = kea
([
`/api/projects/@current/feature_flags/my_flags${encodeParams(params, '?')}`
)
- if (response.status >= 400) {
- toolbarConfigLogic.actions.tokenExpired()
- return []
- }
-
breakpoint()
if (!response.ok) {
return []
diff --git a/frontend/src/toolbar/toolbarConfigLogic.ts b/frontend/src/toolbar/toolbarConfigLogic.ts
index 1b4638b8f39f8..853b03bdeea32 100644
--- a/frontend/src/toolbar/toolbarConfigLogic.ts
+++ b/frontend/src/toolbar/toolbarConfigLogic.ts
@@ -119,10 +119,12 @@ export async function toolbarFetch(
})
if (response.status === 403) {
const responseData = await response.json()
- // Do not try to authenticate if the user has no project access altogether
- if (responseData.detail !== "You don't have access to the project.") {
+ if (responseData.detail === "You don't have access to the project.") {
toolbarConfigLogic.actions.authenticate()
}
}
+ if (response.status == 401) {
+ toolbarConfigLogic.actions.tokenExpired()
+ }
return response
}
diff --git a/frontend/src/toolbar/toolbarLogic.ts b/frontend/src/toolbar/toolbarLogic.ts
deleted file mode 100644
index d5183a6734f20..0000000000000
--- a/frontend/src/toolbar/toolbarLogic.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-import { actions, afterMount, kea, listeners, path, props, reducers, selectors } from 'kea'
-import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
-
-import { actionsTabLogic } from '~/toolbar/actions/actionsTabLogic'
-import { posthog } from '~/toolbar/posthog'
-import { clearSessionToolbarToken } from '~/toolbar/utils'
-import { ToolbarProps } from '~/types'
-
-import type { toolbarLogicType } from './toolbarLogicType'
-
-export const toolbarLogic = kea([
- path(['toolbar', 'toolbarLogic']),
- props({} as ToolbarProps),
-
- actions({
- authenticate: true,
- logout: true,
- tokenExpired: true,
- processUserIntent: true,
- clearUserIntent: true,
- showButton: true,
- hideButton: true,
- }),
-
- reducers(({ props }) => ({
- rawApiURL: [props.apiURL as string],
- rawJsURL: [(props.jsURL || props.apiURL) as string],
- temporaryToken: [props.temporaryToken || null, { logout: () => null, tokenExpired: () => null }],
- actionId: [props.actionId || null, { logout: () => null, clearUserIntent: () => null }],
- userIntent: [props.userIntent || null, { logout: () => null, clearUserIntent: () => null }],
- source: [props.source || null, { logout: () => null }],
- buttonVisible: [true, { showButton: () => true, hideButton: () => false, logout: () => false }],
- dataAttributes: [props.dataAttributes || []],
- posthog: [props.posthog ?? null],
- })),
-
- selectors({
- apiURL: [(s) => [s.rawApiURL], (apiURL) => `${apiURL.endsWith('/') ? apiURL.replace(/\/+$/, '') : apiURL}`],
- jsURL: [
- (s) => [s.rawJsURL, s.apiURL],
- (rawJsURL, apiUrl) =>
- `${rawJsURL ? (rawJsURL.endsWith('/') ? rawJsURL.replace(/\/+$/, '') : rawJsURL) : apiUrl}`,
- ],
- isAuthenticated: [(s) => [s.temporaryToken], (temporaryToken) => !!temporaryToken],
- }),
-
- listeners(({ values, props }) => ({
- authenticate: () => {
- posthog.capture('toolbar authenticate', { is_authenticated: values.isAuthenticated })
- const encodedUrl = encodeURIComponent(window.location.href)
- window.location.href = `${values.apiURL}/authorize_and_redirect/?redirect=${encodedUrl}`
- clearSessionToolbarToken()
- },
- logout: () => {
- posthog.capture('toolbar logout')
- clearSessionToolbarToken()
- },
- tokenExpired: () => {
- posthog.capture('toolbar token expired')
- console.warn('PostHog Toolbar API token expired. Clearing session.')
- if (values.source !== 'localstorage') {
- lemonToast.error('PostHog Toolbar API token expired.')
- }
- clearSessionToolbarToken()
- },
- processUserIntent: () => {
- if (props.userIntent === 'add-action' || props.userIntent === 'edit-action') {
- actionsTabLogic.actions.showButtonActions()
- // the right view will next be opened in `actionsTabLogic` on `getActionsSuccess`
- }
- },
- })),
-
- afterMount(({ props, actions, values }) => {
- if (props.instrument) {
- const distinctId = props.distinctId
- if (distinctId) {
- posthog.identify(distinctId, props.userEmail ? { email: props.userEmail } : {})
- }
- posthog.optIn()
- }
- if (props.userIntent) {
- actions.processUserIntent()
- }
- posthog.capture('toolbar loaded', { is_authenticated: values.isAuthenticated })
- }),
-])