From 585e2525b8528f6cb318b660eb9d971fa245a2ed Mon Sep 17 00:00:00 2001 From: Andries Reitsma Date: Mon, 4 Apr 2022 15:55:07 +0200 Subject: [PATCH 1/3] Update SWR to stable version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40a3f6c..8ccdccb 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "next": "^12.0.4", "react": "^17.0.2", "react-dom": "^17.0.2", - "swr": "^0.3.11" + "swr": "^1.2.2" }, "devDependencies": { "@babel/eslint-parser": "^7.12.1", From 2830603df5659e4058a4b8b3bf80f20a49b7db58 Mon Sep 17 00:00:00 2001 From: Andries Reitsma Date: Mon, 4 Apr 2022 15:57:57 +0200 Subject: [PATCH 2/3] Change revalidate to mutate Part of the upgrade to version 1: https://swr.vercel.app/blog/swr-v1#change-revalidate-to-mutate `useSWR` no longer returns the `revalidate` method, change to `mutate` instead: --- src/hooks/auth.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hooks/auth.js b/src/hooks/auth.js index 333cf7b..7354a65 100644 --- a/src/hooks/auth.js +++ b/src/hooks/auth.js @@ -6,7 +6,7 @@ import { useRouter } from 'next/router' export const useAuth = ({ middleware, redirectIfAuthenticated } = {}) => { const router = useRouter() - const { data: user, error, revalidate } = useSWR('/api/user', () => + const { data: user, error, mutate } = useSWR('/api/user', () => axios .get('/api/user') .then(res => res.data) @@ -26,7 +26,7 @@ export const useAuth = ({ middleware, redirectIfAuthenticated } = {}) => { axios .post('/register', props) - .then(() => revalidate()) + .then(() => mutate()) .catch(error => { if (error.response.status !== 422) throw error @@ -42,7 +42,7 @@ export const useAuth = ({ middleware, redirectIfAuthenticated } = {}) => { axios .post('/login', props) - .then(() => revalidate()) + .then(() => mutate()) .catch(error => { if (error.response.status !== 422) throw error @@ -90,9 +90,9 @@ export const useAuth = ({ middleware, redirectIfAuthenticated } = {}) => { const logout = async () => { if (! error) { - await axios.post('/logout') - - revalidate() + await axios + .post('/logout') + .then(() => mutate()) } window.location.pathname = '/login' From 627f48504e494a87b2ab6c104a455589b4fd0746 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 4 Apr 2022 10:10:27 -0500 Subject: [PATCH 3/3] Update auth.js --- src/hooks/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/auth.js b/src/hooks/auth.js index 7354a65..1b34a6a 100644 --- a/src/hooks/auth.js +++ b/src/hooks/auth.js @@ -92,7 +92,7 @@ export const useAuth = ({ middleware, redirectIfAuthenticated } = {}) => { if (! error) { await axios .post('/logout') - .then(() => mutate()) + .then(() => mutate()) } window.location.pathname = '/login'