Merge pull request #295 from Discours/fix/logout
subscriptions after logout fix
This commit is contained in:
commit
b03b59002a
|
@ -33,7 +33,7 @@ export const AllAuthorsView = (props: AllAuthorsViewProps) => {
|
|||
|
||||
const [searchQuery, setSearchQuery] = createSignal('')
|
||||
|
||||
onMount(() => {
|
||||
createEffect(() => {
|
||||
if (!searchParams().by) {
|
||||
changeSearchParam({
|
||||
by: 'shouts'
|
||||
|
|
|
@ -36,7 +36,7 @@ export const AllTopicsView = (props: AllTopicsViewProps) => {
|
|||
|
||||
const { subscriptions } = useSession()
|
||||
|
||||
onMount(() => {
|
||||
createEffect(() => {
|
||||
if (!searchParams().by) {
|
||||
changeSearchParam({
|
||||
by: 'shouts'
|
||||
|
|
|
@ -41,12 +41,14 @@ export function useSession() {
|
|||
return useContext(SessionContext)
|
||||
}
|
||||
|
||||
export const SessionProvider = (props: { children: JSX.Element }) => {
|
||||
const [isSessionLoaded, setIsSessionLoaded] = createSignal(false)
|
||||
const [subscriptions, setSubscriptions] = createSignal<MySubscriptionsQueryResult>({
|
||||
const EMPTY_SUBSCRIPTIONS = {
|
||||
topics: [],
|
||||
authors: []
|
||||
})
|
||||
}
|
||||
|
||||
export const SessionProvider = (props: { children: JSX.Element }) => {
|
||||
const [isSessionLoaded, setIsSessionLoaded] = createSignal(false)
|
||||
const [subscriptions, setSubscriptions] = createSignal<MySubscriptionsQueryResult>(EMPTY_SUBSCRIPTIONS)
|
||||
const { t } = useLocalize()
|
||||
const {
|
||||
actions: { showSnackbar }
|
||||
|
@ -74,7 +76,11 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
|
|||
|
||||
const loadSubscriptions = async (): Promise<void> => {
|
||||
const result = await apiClient.getMySubscriptions()
|
||||
if (result) {
|
||||
setSubscriptions(result)
|
||||
} else {
|
||||
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
||||
}
|
||||
}
|
||||
|
||||
const [session, { refetch: loadSession, mutate }] = createResource<AuthResult>(getSession, {
|
||||
|
@ -96,9 +102,11 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
|
|||
|
||||
const [isAuthWithCallback, setIsAuthWithCallback] = createSignal(null)
|
||||
|
||||
const requireAuthentication = (callback: () => void, modalSource: AuthModalSource) => {
|
||||
const requireAuthentication = async (callback: () => void, modalSource: AuthModalSource) => {
|
||||
setIsAuthWithCallback(() => callback)
|
||||
|
||||
await loadSession()
|
||||
|
||||
if (!isAuthenticated()) {
|
||||
showModal('auth', modalSource)
|
||||
}
|
||||
|
@ -120,6 +128,7 @@ export const SessionProvider = (props: { children: JSX.Element }) => {
|
|||
// TODO: call backend to revoke token
|
||||
mutate(null)
|
||||
resetToken()
|
||||
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
||||
showSnackbar({ body: t("You've successfully logged out") })
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user