Refactor authActions module
Refactor authActions.ts into smaller files for better maintainability and readability.
This commit is contained in:
32
src/contexts/auth/auth.utils.ts
Normal file
32
src/contexts/auth/auth.utils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
import { toast } from '@/hooks/useToast.wrapper';
|
||||
import { supabase } from '@/lib/supabase';
|
||||
|
||||
// 토스트 메시지 표시 유틸리티 함수
|
||||
export const showAuthToast = (title: string, description: string, variant: 'default' | 'destructive' = 'default') => {
|
||||
toast({ title, description, variant });
|
||||
};
|
||||
|
||||
// 에러 메시지 처리 유틸리티 함수
|
||||
export const handleNetworkError = (error: any): string => {
|
||||
return error.message && error.message.includes('fetch')
|
||||
? '서버 연결에 실패했습니다. 네트워크 연결을 확인해주세요.'
|
||||
: (error.message || '예상치 못한 오류가 발생했습니다.');
|
||||
};
|
||||
|
||||
// 응답 파싱 유틸리티 함수
|
||||
export const parseResponse = async (response: Response) => {
|
||||
try {
|
||||
const responseText = await response.text();
|
||||
console.log('응답 원본:', responseText);
|
||||
|
||||
if (!responseText || responseText.trim() === '') {
|
||||
throw new Error('서버가 빈 응답을 반환했습니다');
|
||||
}
|
||||
|
||||
return JSON.parse(responseText);
|
||||
} catch (parseError) {
|
||||
console.error('응답 파싱 오류:', parseError);
|
||||
throw parseError;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user