Update labels and refine hooks for teams and billing modules

This commit modifies several language labels and refines hooks related to 'teams' and 'billing' modules for better clarity and consistency. It also includes the deletion of unused locale files and package dependencies transfered to 'peerDependencies'. Lastly, it introduces minor enhancements in server command, error logging functionality, and scripts to interact with Stripe.
This commit is contained in:
giancarlo
2024-03-26 23:32:28 +08:00
parent 4032aed827
commit e402caff30
52 changed files with 1227 additions and 1049 deletions

View File

@@ -3,7 +3,7 @@ import { createBrowserClient } from '@supabase/ssr';
import { Database } from '../database.types';
let client: ReturnType<typeof createBrowserClient>;
let client: ReturnType<typeof createBrowserClient<Database>>;
export function getSupabaseBrowserClient<GenericSchema = Database>() {
const SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL;
@@ -12,7 +12,9 @@ export function getSupabaseBrowserClient<GenericSchema = Database>() {
invariant(SUPABASE_URL, `Supabase URL was not provided`);
invariant(SUPABASE_ANON_KEY, `Supabase Anon key was not provided`);
if (client) return client;
if (client) {
return client;
}
client = createBrowserClient<GenericSchema>(SUPABASE_URL, SUPABASE_ANON_KEY);

View File

@@ -28,7 +28,6 @@ function AuthRedirectListener({
useEffect(() => {
// keep this running for the whole session unless the component was unmounted
const listener = client.auth.onAuthStateChange((_, user) => {
console.log(_, user);
// log user out if user is falsy
// and if the current path is a private route
const shouldRedirectUser = !user && isPrivateRoute(pathName);
@@ -47,10 +46,6 @@ function AuthRedirectListener({
void router.refresh();
}
}
if (user && isPrivateRoute(pathName)) {
return revalidateUserSession();
}
});
// destroy listener on un-mounts

View File

@@ -1,16 +1,15 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useSupabase } from './use-supabase';
import { useRevalidateUserSession } from './use-user-session';
export function useSignOut() {
const client = useSupabase();
const revalidateUserSession = useRevalidateUserSession();
const queryClient = useQueryClient();
return useMutation({
mutationFn: async () => {
await client.auth.signOut();
await revalidateUserSession();
await queryClient.invalidateQueries();
},
});
}

View File

@@ -8,7 +8,7 @@ type Params = UserAttributes & { redirectTo: string };
export function useUpdateUser() {
const client = useSupabase();
const mutationKey = ['auth', 'update-user'];
const mutationKey = ['supabase:user'];
const mutationFn = async (attributes: Params) => {
const { redirectTo, ...params } = attributes;
@@ -17,10 +17,14 @@ export function useUpdateUser() {
emailRedirectTo: redirectTo,
});
console.log(response);
if (response.error) {
throw response.error;
}
console.log('response.data:', response.data);
return response.data;
};

View File

@@ -7,7 +7,7 @@ import { useSupabase } from './use-supabase';
export function useUser() {
const client = useSupabase();
const router = useRouter();
const queryKey = ['user'];
const queryKey = ['supabase:user'];
const queryFn = async () => {
const response = await client.auth.getUser();