Think it might be ready to deploy. I'm sure there are a lot of bugs, but I at least am no longe finding them

This commit is contained in:
2025-06-16 05:33:57 -05:00
parent bc915275cf
commit a28af1f629
5 changed files with 45 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import React, {
} from 'react'; } from 'react';
import { import {
getProfile, getProfile,
getProfileWithAvatar,
getUser, getUser,
updateProfile as updateProfileAction, updateProfile as updateProfileAction,
} from '@/lib/hooks'; } from '@/lib/hooks';
@ -50,7 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
} }
const userResponse = await getUser(); const userResponse = await getUser();
const profileResponse = await getProfile(); const profileResponse = await getProfileWithAvatar();
if (!userResponse.success || !profileResponse.success) { if (!userResponse.success || !profileResponse.success) {
setUser(null); setUser(null);

View File

@ -1,10 +1,40 @@
'use server'; 'use client';
import { createServerClient, type Profile } from '@/utils/supabase'; import { createServerClient, type Profile } from '@/utils/supabase';
import { getSignedUrl, getUser } from '@/lib/hooks'; import { getSignedUrl, getUser } from '@/lib/actions';
import type { Result } from '.'; import type { Result } from '.';
export const getProfile = async ( export const getProfile = async (
userId: string | null = null,
): Promise<Result<Profile>> => {
try {
if (userId == null) {
const user = await getUser();
if (!user.success || !user.data.id)
throw new Error('User not found');
userId = user.data.id;
}
const supabase = await createServerClient();
const { data, error } = await supabase
.from('profiles')
.select('*')
.eq('id', userId)
.single();
if (error) throw error;
return { success: true, data: data as Profile };
} catch (error) {
return {
success: false,
error:
error instanceof Error
? error.message
: 'Unknown error getting profile',
};
}
};
export const getProfileWithAvatar = async (
userId: string | null = null userId: string | null = null
): Promise<Result<Profile>> => { ): Promise<Result<Profile>> => {
try { try {
@ -48,7 +78,7 @@ type updateProfileProps = {
full_name?: string; full_name?: string;
email?: string; email?: string;
avatar_url?: string; avatar_url?: string;
provider?: string provider?: string;
}; };
export const updateProfile = async ({ export const updateProfile = async ({

View File

@ -1,7 +1,7 @@
'use server'; 'use server';
import { createServerClient } from '@/utils/supabase'; import { createServerClient } from '@/utils/supabase';
import type { Profile, Result } from '@/utils/supabase'; import type { Profile, Result } from '@/utils/supabase';
import { getUser, getProfile, getSignedUrl } from '@/lib/actions'; import { getUser, getProfileWithAvatar, getSignedUrl } from '@/lib/actions';
export type UserWithStatus = { export type UserWithStatus = {
id?: string; id?: string;
@ -67,9 +67,9 @@ export const getRecentUsersWithStatuses = async (): Promise<
for (const userWithStatus of filtered) { for (const userWithStatus of filtered) {
if (userWithStatus.user.avatar_url) if (userWithStatus.user.avatar_url)
userWithStatus.user.avatar_url = userWithStatus.user.avatar_url =
await getAvatarUrl(userWithStatus.updated_by?.avatar_url); await getAvatarUrl(userWithStatus.user.avatar_url);
if (userWithStatus.updated_by?.avatar_url) if (userWithStatus.updated_by?.avatar_url)
userWithStatus.user.avatar_url = userWithStatus.updated_by.avatar_url =
await getAvatarUrl(userWithStatus.updated_by?.avatar_url); await getAvatarUrl(userWithStatus.updated_by?.avatar_url);
filteredWithAvatars.push(userWithStatus); filteredWithAvatars.push(userWithStatus);
} }
@ -115,7 +115,7 @@ export const updateStatuses = async (
): Promise<Result<void>> => { ): Promise<Result<void>> => {
try { try {
const supabase = await createServerClient(); const supabase = await createServerClient();
const profileResponse = await getProfile(); const profileResponse = await getProfileWithAvatar();
if (!profileResponse.success) throw new Error('Not authenticated!'); if (!profileResponse.success) throw new Error('Not authenticated!');
const user = profileResponse.data; const user = profileResponse.data;
@ -155,7 +155,7 @@ export const updateUserStatus = async (
): Promise<Result<void>> => { ): Promise<Result<void>> => {
try { try {
const supabase = await createServerClient(); const supabase = await createServerClient();
const profileResponse = await getProfile(); const profileResponse = await getProfileWithAvatar();
if (!profileResponse.success) if (!profileResponse.success)
throw new Error(`Not authenticated! ${profileResponse.error}`); throw new Error(`Not authenticated! ${profileResponse.error}`);
const userProfile = profileResponse.data; const userProfile = profileResponse.data;

View File

@ -4,7 +4,7 @@ import { createClient, type Profile } from '@/utils/supabase';
import { getSignedUrl, getUser } from '@/lib/hooks'; import { getSignedUrl, getUser } from '@/lib/hooks';
import type { Result } from '.'; import type { Result } from '.';
export const getOriginalProfile = async ( export const getProfile = async (
userId: string | null = null, userId: string | null = null,
): Promise<Result<Profile>> => { ): Promise<Result<Profile>> => {
try { try {
@ -34,7 +34,7 @@ export const getOriginalProfile = async (
} }
}; };
export const getProfile = async ( export const getProfileWithAvatar = async (
userId: string | null = null userId: string | null = null
): Promise<Result<Profile>> => { ): Promise<Result<Profile>> => {
try { try {

View File

@ -1,7 +1,7 @@
'use client'; 'use client';
import { createClient } from '@/utils/supabase'; import { createClient } from '@/utils/supabase';
import type { Profile, Result } from '@/utils/supabase'; import type { Profile, Result } from '@/utils/supabase';
import { getUser, getOriginalProfile, getSignedUrl } from '@/lib/hooks'; import { getUser, getProfileWithAvatar, getSignedUrl } from '@/lib/hooks';
export type UserWithStatus = { export type UserWithStatus = {
id?: string; id?: string;
@ -115,7 +115,7 @@ export const updateStatuses = async (
): Promise<Result<void>> => { ): Promise<Result<void>> => {
try { try {
const supabase = createClient(); const supabase = createClient();
const profileResponse = await getOriginalProfile(); const profileResponse = await getProfileWithAvatar();
if (!profileResponse.success) throw new Error('Not authenticated!'); if (!profileResponse.success) throw new Error('Not authenticated!');
const user = profileResponse.data; const user = profileResponse.data;
@ -155,7 +155,7 @@ export const updateUserStatus = async (
): Promise<Result<void>> => { ): Promise<Result<void>> => {
try { try {
const supabase = createClient(); const supabase = createClient();
const profileResponse = await getOriginalProfile(); const profileResponse = await getProfileWithAvatar();
if (!profileResponse.success) if (!profileResponse.success)
throw new Error(`Not authenticated! ${profileResponse.error}`); throw new Error(`Not authenticated! ${profileResponse.error}`);
const userProfile = profileResponse.data; const userProfile = profileResponse.data;