The changes add user session handling directly in the middleware. This ensures the user data is fetched at the start of a request and then passed on to route handlers, reducing repeated data fetching. Also, these improvements include adjustments for how sign-out and auth-change events are managed, particularly when the user session state changes. Additionally, it corrects the error response from useUser hook to return `undefined` instead of `null`.
14 lines
268 B
TypeScript
14 lines
268 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
|
|
import { useSupabase } from './use-supabase';
|
|
|
|
export function useSignOut() {
|
|
const client = useSupabase();
|
|
|
|
return useMutation({
|
|
mutationFn: async () => {
|
|
await client.auth.signOut();
|
|
},
|
|
});
|
|
}
|