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:
@ -10,6 +10,7 @@ import React, {
|
||||
} from 'react';
|
||||
import {
|
||||
getProfile,
|
||||
getProfileWithAvatar,
|
||||
getUser,
|
||||
updateProfile as updateProfileAction,
|
||||
} from '@/lib/hooks';
|
||||
@ -50,7 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
||||
}
|
||||
|
||||
const userResponse = await getUser();
|
||||
const profileResponse = await getProfile();
|
||||
const profileResponse = await getProfileWithAvatar();
|
||||
|
||||
if (!userResponse.success || !profileResponse.success) {
|
||||
setUser(null);
|
||||
|
@ -1,10 +1,40 @@
|
||||
'use server';
|
||||
'use client';
|
||||
|
||||
import { createServerClient, type Profile } from '@/utils/supabase';
|
||||
import { getSignedUrl, getUser } from '@/lib/hooks';
|
||||
import { getSignedUrl, getUser } from '@/lib/actions';
|
||||
import type { Result } from '.';
|
||||
|
||||
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
|
||||
): Promise<Result<Profile>> => {
|
||||
try {
|
||||
@ -48,7 +78,7 @@ type updateProfileProps = {
|
||||
full_name?: string;
|
||||
email?: string;
|
||||
avatar_url?: string;
|
||||
provider?: string
|
||||
provider?: string;
|
||||
};
|
||||
|
||||
export const updateProfile = async ({
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use server';
|
||||
import { createServerClient } 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 = {
|
||||
id?: string;
|
||||
@ -67,9 +67,9 @@ export const getRecentUsersWithStatuses = async (): Promise<
|
||||
for (const userWithStatus of filtered) {
|
||||
if (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)
|
||||
userWithStatus.user.avatar_url =
|
||||
userWithStatus.updated_by.avatar_url =
|
||||
await getAvatarUrl(userWithStatus.updated_by?.avatar_url);
|
||||
filteredWithAvatars.push(userWithStatus);
|
||||
}
|
||||
@ -115,7 +115,7 @@ export const updateStatuses = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = await createServerClient();
|
||||
const profileResponse = await getProfile();
|
||||
const profileResponse = await getProfileWithAvatar();
|
||||
if (!profileResponse.success) throw new Error('Not authenticated!');
|
||||
const user = profileResponse.data;
|
||||
|
||||
@ -155,7 +155,7 @@ export const updateUserStatus = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = await createServerClient();
|
||||
const profileResponse = await getProfile();
|
||||
const profileResponse = await getProfileWithAvatar();
|
||||
if (!profileResponse.success)
|
||||
throw new Error(`Not authenticated! ${profileResponse.error}`);
|
||||
const userProfile = profileResponse.data;
|
||||
|
@ -4,7 +4,7 @@ import { createClient, type Profile } from '@/utils/supabase';
|
||||
import { getSignedUrl, getUser } from '@/lib/hooks';
|
||||
import type { Result } from '.';
|
||||
|
||||
export const getOriginalProfile = async (
|
||||
export const getProfile = async (
|
||||
userId: string | null = null,
|
||||
): Promise<Result<Profile>> => {
|
||||
try {
|
||||
@ -34,7 +34,7 @@ export const getOriginalProfile = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const getProfile = async (
|
||||
export const getProfileWithAvatar = async (
|
||||
userId: string | null = null
|
||||
): Promise<Result<Profile>> => {
|
||||
try {
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import { createClient } 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 = {
|
||||
id?: string;
|
||||
@ -115,7 +115,7 @@ export const updateStatuses = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = createClient();
|
||||
const profileResponse = await getOriginalProfile();
|
||||
const profileResponse = await getProfileWithAvatar();
|
||||
if (!profileResponse.success) throw new Error('Not authenticated!');
|
||||
const user = profileResponse.data;
|
||||
|
||||
@ -155,7 +155,7 @@ export const updateUserStatus = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = createClient();
|
||||
const profileResponse = await getOriginalProfile();
|
||||
const profileResponse = await getProfileWithAvatar();
|
||||
if (!profileResponse.success)
|
||||
throw new Error(`Not authenticated! ${profileResponse.error}`);
|
||||
const userProfile = profileResponse.data;
|
||||
|
Reference in New Issue
Block a user