Next.js Discord

Discord Forum

sanctum laravel authentication

Unanswered
Crème D’Argent posted this in #help-forum
Open in Discord
Crème D’ArgentOP
Hi all,
I am using nextjs with laravel and sanctum authentication.

File: hooks/useAuth.ts

const {data: user, error, mutate} = useSWR('/api/user', () =>
axios.get('profile')
.then(res => res.data.data)
.catch(error => {
if (error.response.status !== 409) throw error
}))

and when I am using useAuth(); in any public page for example /login page or in header page to check whether user is logged-in or not, the /api/user is keep calling until logged-in successfully.

and that cost unnecessary request to endpoint

can anyone please advise me on that case?

0 Replies