Skip to content

How create a /logout route (how to call mutation on page load) #4058

Answered by tordans
tordans asked this question in Q&A
Discussion options

You must be logged in to vote

The part that had to ask for help for to figure out is, how to void-call the async mutation function in a useEffect.

This is my page in src/pages/auth/logout.tsx

The button part could be removed, it is never visible to users anymore.
The const next part could likely be simplified to be just / for most apps; I just kept it was and did not investigate further.
The "componentDidMount"-useEffect might not need the useEffect but in then a guard is needed so it only runs in the browser; did not investigate further.

(This is a Next 12 app.)

import { BlitzPage } from "@blitzjs/next"
import { useMutation } from "@blitzjs/rpc"
import { useRouter } from "next/router"
import { useEffect } from "react"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tordans
Comment options

Answer selected by tordans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant