「NAVER IDへのログイン」ボタンを閉じる
12545 ワード
環境:Realt、NodeJS、PostCSS
(前)
(後)
開発者ツールには、次のものが含まれています.
Customの流れは、
NAVERで作成したボタンをcss
userefを使用してCustomボタンをクリックすると、非表示のNAVERボタンのaラベルがクリックされます.
1.カスタム結果のプレビュー
(前)
(後)
2.方法
naverLogin.init()
をすると、設定された({color: "green",type: 3,height: 55}
)スタイルの登録ボタンが発生します.開発者ツールには、次のものが含まれています.
Customの流れは、
NAVERで作成したボタンをcss
display:none
として非表示にし、Customボタンで代用します.userefを使用してCustomボタンをクリックすると、非表示のNAVERボタンのaラベルがクリックされます.
3.コード
// components/Naver/naver.jsx
import React, { useEffect, useRef } from 'react'
import * as config from '../../config';
import styles from './naver.module.css';
function Naver() {
const naverRef = useRef();
useEffect(() => {
const naverScript = document.createElement("script");
naverScript.src = "https://static.nid.naver.com/js/naveridlogin_js_sdk_2.0.2.js";
naverScript.type = "text/javascript";
document.head.appendChild(naverScript);
naverScript.onload = () => {
const naverLogin = new window.naver.LoginWithNaverId({
clientId: config.NAVER_CLIENT,
callbackUrl: "http://localhost:3000/oauth/callback/naver",
callbackHandle: true,
isPopup: false,
loginButton: {
color: "green",
type: 3,
height: 55,
}
});
naverLogin.init();
naverLogin.logout(); //네이버 로그인이 계속 유지되는 경우가 있음, 초기화시 로그아웃
}
}, [])
const handleClick = () => {
naverRef.current.children[0].click();
}
return (
<>
<div ref={naverRef} id="naverIdLogin"></div>
<button onClick={handleClick} className={styles.naver} >
<img src="/images/naver.jpg" alt="naver" />
Login with Naver
</button>
</>
)
}
そして正式な書類のデザインガイドに従って造形して終わりました.🥳// index.css
#naverIdLogin{
display: none;
}
// components/Naver/naver.module.css
.naver{
padding: 0.6em 1em;
border-radius: 0.25em;
font-size: 0.8rem;
margin-top: 0.7em;
display: flex;
align-items: center;
font-weight: 400;
box-shadow: var(--shadow-1);
background-color: #03C75A;
color: white;
}
.naver img{
height:0.9rem;
margin-right: 0.7em;
margin-left: 0.2em;
}
Reference
この問題について(「NAVER IDへのログイン」ボタンを閉じる), 我々は、より多くの情報をここで見つけました https://velog.io/@wiostz98kr/네아로네이버-아이디로-로그인하기-버튼-커스텀하기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol