2026, 새로운 도약을 시작합니다.

소셜로그인 클라이언트 변경하는 경우

소셜로그인 하다보면 부득이하게 소셜로그인 클라이언트 아이디를 변경하게 되는데
변경하고나면 기존 회원이 로그인이 아닌 회원가입으로 페이지 전환이 된다.

같은 이메일 주소인 경우 Identifier를 업데이트하도록 하는 로직입니다.

<code>

// plugin/social/includes/functions.php:547 추가

// 함수 내 global $g5 추가 

// --- [ADD] 이메일 기반 재매핑: 클라이언트 변경으로 identifier가 바뀐 경우 병합 후 로그인 ---

            if (! $is_member && !empty($user_profile)) {
                // 네이버 응답: 이메일 동의가 되어 있어야 값이 온다 (emailVerified 우선)
                $email = '';
                if (property_exists($user_profile, 'emailVerified') && $user_profile->emailVerified) {
                    $email = strtolower(trim($user_profile->emailVerified));
                } elseif (property_exists($user_profile, 'email') && $user_profile->email) {
                    $email = strtolower(trim($user_profile->email));
                }

                if ($email) {
                    // 1) 동일 이메일 회원 존재 여부
                    $mb = sql_fetch("SELECT mb_id, mb_email, mb_leave_date, mb_intercept_date FROM {$g5['member_table']} WHERE mb_email = '".sql_real_escape_string($email)."'");
                    if ($mb && $mb['mb_id'] && empty($mb['mb_leave_date']) && empty($mb['mb_intercept_date'])) {
            
                        // 2) 같은 이메일에 연결된 기존 소셜 레코드(예전 identifier)를 찾는다
                        $old = sql_fetch("
                            SELECT mp_no, provider, identifier, mb_id
                            FROM {$g5['social_profile_table']}
                            WHERE provider='naver' AND mb_id='".sql_real_escape_string($mb['mb_id'])."'
                            ORDER BY mp_no DESC
                            LIMIT 1
                        ");
            
                        // 3) 현재 로그인 시도한 네이버의 새 identifier
                        $new_identifier = $user_profile->identifier; // Hybridauth profile->identifier (네이버 uid 매핑) 
            
                        // 4) 이미 새 identifier로 연결되어 있다면 바로 로그인
                        if ($old && $old['mb_id'] && $old['identifier'] === $new_identifier) {
                            // 바로 로그인 처리 (기존 로직과 동일)
                            $mb_password = sha1( str_shuffle( "0123456789abcdefghijklmnoABCDEFGHIJ" ) );
                            echo social_return_from_provider_page($provider_name, $login_action_url, $mb['mb_id'], $mb_password, $url, $use_popup);
                            exit;
                        }
            
                        // 5) 다른 계정에 이미 새 identifier가 묶여 있지 않은지 방어
                        $dup = sql_fetch("
                            SELECT COUNT(*) AS cnt
                            FROM {$g5['social_profile_table']}
                            WHERE provider='naver' AND identifier='".sql_real_escape_string($new_identifier)."'
                        ");
                        if (intval($dup['cnt']) > 0) {
                            // 동일 네이버 계정이 다른 계정에 연결된 상태 -> 충돌 안내
                            $msg = '동일 네이버 계정이 이미 다른 계정과 연결되어 있어 자동 병합할 수 없습니다.';
                            if ($use_popup == 1 || ! $use_popup) alert_close($msg); else alert($msg);
                            if (is_object($adapter)) social_logout_with_adapter($adapter);
                            exit;
                        }
            
                        // 6) 기존 소셜 레코드가 있으면 identifier만 새 값으로 업데이트(클라이언트 변경 대응)
                        if ($old && $old['mp_no']) {
                            sql_query("
                                UPDATE {$g5['social_profile_table']}
                                SET identifier = '".sql_real_escape_string($new_identifier)."', mp_latest_day = '".G5_TIME_YMDHIS."'
                                WHERE mp_no = ".intval($old['mp_no'])."
                            ");
                        } else {
                            // 과거 소셜 레코드가 없었다면 새 레코드로 연결
                            // 필요한 필드만 최소 입력. 세부 프로필은 social_user_profile_replace가 갱신
                            sql_query("
                                INSERT INTO {$g5['social_profile_table']}
                                    (mb_id, provider, identifier, mp_register_day, mp_latest_day)
                                VALUES
                                    ('".sql_real_escape_string($mb['mb_id'])."', 'naver', '".sql_real_escape_string($new_identifier)."', '".G5_TIME_YMDHIS."', '".G5_TIME_YMDHIS."')
                            ");
                        }
            
                        // 7) 최신 프로필 저장 및 로그인
                        social_user_profile_replace($mb['mb_id'], $provider_name, $user_profile);
                        set_session('ss_social_provider', $provider_name);
            
                        // 팝업/일반 로그인 처리 동일하게 반환
                        $mb_password = sha1( str_shuffle( "0123456789abcdefghijklmnoABCDEFGHIJ" ) );
                        echo social_return_from_provider_page($provider_name, $login_action_url, $mb['mb_id'], $mb_password, $url, $use_popup);
                        exit;
                    }
                }
            }
            // --- [END ADD] 이메일 기반 재매핑 ---

</code>

|

댓글 2개

아직까진 소셜로그인을 사용하는 곳들 클라이언트를 변경한 적이 없지만 언젠간 발생할 수도 있을 법한 이슈라...

감사합니다!

감사합니다

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,593
2741 어제 조회 78
2740 3일 전 조회 83
2739 1주 전 조회 195
2738 1주 전 조회 201
2737 1주 전 조회 169
2736 1주 전 조회 269
2735 2주 전 조회 274
2734 3주 전 조회 255
2733 1개월 전 조회 258
2732 1개월 전 조회 293
2731 1개월 전 조회 261
2730 1개월 전 조회 218
2729 1개월 전 조회 344
2728 1개월 전 조회 238
2727 1개월 전 조회 413
2726 1개월 전 조회 248
2725 1개월 전 조회 323
2724 1개월 전 조회 352
2723 1개월 전 조회 260
2722 1개월 전 조회 293
2721 1개월 전 조회 206
2720 2개월 전 조회 299
2719 2개월 전 조회 302
2718 2개월 전 조회 196
2717 2개월 전 조회 329
2716 2개월 전 조회 198
2715 2개월 전 조회 306
2714 2개월 전 조회 266
2713 2개월 전 조회 369
2712 2개월 전 조회 284
🐛 버그신고