feat: 댓글 신고·차단·약관 동의(관리 스크립트 포함), 구글 로그인(서버·웹·안드로이드 앱), 앱 패키지 kr.o2o.nalssigak·versionCode 1000
This commit is contained in:
1 parent
fbebdcb796
commit
3f3a3ea039
35 files changed
+1723
-115
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { authConfigOptions, googleLoginMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { ResAuth } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { GoogleSignin, isErrorWithCode, isSuccessResponse, statusCodes } from '@react-native-google-signin/google-signin';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { useState } from 'react';
|
||||
import { Platform, Pressable, View } from 'react-native';
|
||||
import { Text } from '@/components/text';
|
||||
|
||||
/** 구글로 계속하기. 서버에 클라이언트 ID가 없거나 안드로이드가 아니면 그리지 않는다 */
|
||||
export function GoogleButton({ onResult, onFail }: { onResult: (res: ResAuth) => void; onFail: () => void }) {
|
||||
const clientId = useQuery({ ...authConfigOptions(), staleTime: Infinity, enabled: Platform.OS === 'android' }).data?.google_client_id;
|
||||
const login = useMutation(googleLoginMutation());
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [broken, setBroken] = useState(false);
|
||||
|
||||
const press = async () => {
|
||||
if (!clientId) return;
|
||||
setBroken(false);
|
||||
setBusy(true);
|
||||
try {
|
||||
GoogleSignin.configure({ webClientId: clientId });
|
||||
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
|
||||
const res = await GoogleSignin.signIn();
|
||||
if (!isSuccessResponse(res)) return;
|
||||
const token = res.data.idToken;
|
||||
if (!token) return onFail();
|
||||
login.mutate({ body: { credential: token } }, { onSuccess: onResult, onError: onFail });
|
||||
} catch (e) {
|
||||
if (isErrorWithCode(e) && e.code === statusCodes.IN_PROGRESS) return;
|
||||
console.error('[google] sign in', e);
|
||||
setBroken(true);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (Platform.OS !== 'android' || !clientId) return null;
|
||||
const pending = busy || login.isPending;
|
||||
return (
|
||||
<View className="gap-2">
|
||||
<Pressable onPress={press} disabled={pending} className="rounded-full border-[1.5px] border-line bg-white p-3 disabled:opacity-60" accessibilityRole="button">
|
||||
<Text className="text-center text-[15px] font-extrabold text-[#28304a]">{pending ? '구글로 로그인 중…' : '구글로 계속하기'}</Text>
|
||||
</Pressable>
|
||||
{broken && <Text className="text-center text-[13px] font-bold text-ink3">구글 로그인을 하지 못했어요. 아이디로 로그인해 주세요.</Text>}
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View className="h-px flex-1 bg-line" />
|
||||
<Text className="text-[12.5px] font-bold text-ink3">또는 아이디로</Text>
|
||||
<View className="h-px flex-1 bg-line" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user