Ramble-FE / hooks / useOAuth.ts
useOAuth.ts
Raw
import { OAUTH_CONFIGS } from "@/config";
import { UseOAuthProps } from "@/types";
import { APP_SCHEME, getClientId } from "@/utils";
import { makeRedirectUri, useAuthRequest } from "expo-auth-session";
import Constants from "expo-constants";
import { useMemo } from "react";
import { useOAuthCore } from "./useOAuthCore";

export function useOAuth({ onSuccess, onError }: UseOAuthProps) {
    const redirectUri = useMemo(() => makeRedirectUri({ scheme: APP_SCHEME }), []);
    const appleClientId = useMemo(() => getClientId("apple"), []);

    // Google OAuth 설정
    const [requestGoogle, responseGoogle, promptAsyncGoogle] = useAuthRequest(
        {
            clientId: Constants.expoConfig?.extra?.googleClientIdWeb,
            scopes: OAUTH_CONFIGS.google.scopes,
            redirectUri,
        },
        OAUTH_CONFIGS.google.discovery
    );

    // Apple OAuth 설정
    const [requestApple, responseApple, promptAsyncApple] = useAuthRequest(
        {
            clientId: appleClientId,
            scopes: OAUTH_CONFIGS.apple.scopes,
            redirectUri,
        },
        OAUTH_CONFIGS.apple.discovery
    );

    return useOAuthCore({
        onSuccess,
        onError,
        responseGoogle,
        requestGoogle,
        responseApple,
        requestApple,
        promptAsyncGoogle,
        promptAsyncApple,
    });
}