:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { MakeLogicType, actions, afterMount, kea, path } from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
import api from 'lib/api'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface unsubscribeLogicValues {
unsubscription: boolean
unsubscriptionLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface unsubscribeLogicActions {
attemptUnsubscribe: (token: string) => {
token: string
}
attemptUnsubscribeFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
attemptUnsubscribeSuccess: (
unsubscription: boolean,
payload?: {
token: string
}
) => {
unsubscription: boolean
payload?: {
token: string
}
}
}
export type unsubscribeLogicType = MakeLogicType<unsubscribeLogicValues, unsubscribeLogicActions>
export const unsubscribeLogic = kea<unsubscribeLogicType>([
path(['scenes', 'Unsubscribe', 'unsubscribeLogic']),
actions({
attemptUnsubscribe: (token: string) => ({ token }),
}),
loaders(() => ({
unsubscription: {
__default: false as boolean,
attemptUnsubscribe: async ({ token }) => {
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.
const res = await api.get(`api/unsubscribe?token=${token}`)
return res.success
},
},
})),
afterMount(({ actions }) => {
const { token } = router.values.searchParams
actions.attemptUnsubscribe(token)
}),
])