Refactor code and update dependencies configuration

This commit includes reorganizing dependencies in 'package.json' for better readability. It also refactors code associated with user and personal account data along with animations for AvatarFallback and profile name display. Additionally, the 'next' package version has been updated to '14.2.0-canary.56'. Some changes have been made for minor corrections and enhancements in the scripts.
This commit is contained in:
giancarlo
2024-04-04 11:02:27 +08:00
parent 5c5532dc22
commit 64fca41f8d
12 changed files with 97 additions and 82 deletions

View File

@@ -84,9 +84,13 @@ export function AuthChangeListener({
);
}
/**
* Determines if a given path is a private route.
*
* @param {string} path - The path to check.
*/
function isPrivateRoute(path: string) {
// TODO: use config
const prefixes = ['/home', '/admin', '/password-reset'];
const prefixes = ['/home', '/admin', '/join', '/update-password'];
return prefixes.some((prefix) => path.startsWith(prefix));
}

View File

@@ -1,5 +1,3 @@
import { useRouter } from 'next/navigation';
import type { User } from '@supabase/supabase-js';
import { useQuery } from '@tanstack/react-query';
@@ -10,14 +8,13 @@ const queryKey = ['supabase:user'];
export function useUser(initialData?: User | null) {
const client = useSupabase();
const router = useRouter();
const queryFn = async () => {
const response = await client.auth.getUser();
// this is most likely a session error or the user is not logged in
if (response.error) {
throw router.replace('/');
return null;
}
if (response.data?.user) {
@@ -32,6 +29,5 @@ export function useUser(initialData?: User | null) {
queryKey,
initialData,
refetchOnWindowFocus: false,
refetchOnMount: false,
});
}