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,596
2681 3개월 전 조회 435
2680 4개월 전 조회 567
2679 4개월 전 조회 344
2678 4개월 전 조회 364
2677 4개월 전 조회 333
2676 4개월 전 조회 359
2675 4개월 전 조회 527
2674 4개월 전 조회 687
2673 4개월 전 조회 466
2672 4개월 전 조회 341
2671 4개월 전 조회 562
2670 4개월 전 조회 344
2669 4개월 전 조회 412
2668 4개월 전 조회 303
2667 4개월 전 조회 306
2666 4개월 전 조회 396
2665 4개월 전 조회 322
2664 4개월 전 조회 566
2663 4개월 전 조회 535
2662 4개월 전 조회 458
2661 5개월 전 조회 633
2660 5개월 전 조회 899
2659 5개월 전 조회 610
2658 5개월 전 조회 578
2657 5개월 전 조회 654
2656 5개월 전 조회 782
2655 5개월 전 조회 469
2654 5개월 전 조회 523
2653 5개월 전 조회 1,204
2652 6개월 전 조회 636
🐛 버그신고