add new yandex auth
This commit is contained in:
@@ -14,10 +14,6 @@ export default function YandexAuthWithScript() {
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
const [showButton, setShowButton] = useState(true);
|
||||
|
||||
const handleLogin = (token: string) => {
|
||||
console.log('handleLogin');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isReady || !buttonRef.current || !window.YaAuthSuggest) return;
|
||||
|
||||
@@ -25,31 +21,28 @@ export default function YandexAuthWithScript() {
|
||||
{
|
||||
client_id: 'b356a7ceac0f4c50a3b434220f86bce0',
|
||||
response_type: 'token',
|
||||
redirect_uri: `http://localhost:2999/ru/login`,
|
||||
redirect_uri: `https://fallibly-desired-moonfish.cloudpub.ru/en/login`,
|
||||
},
|
||||
'http://localhost:2999',
|
||||
'https://fallibly-desired-moonfish.cloudpub.ru',
|
||||
{
|
||||
parentId: buttonRef.current.id,
|
||||
view: 'button',
|
||||
buttonView: 'main',
|
||||
buttonTheme: 'light',
|
||||
buttonSize: 'm',
|
||||
buttonSize: 'l',
|
||||
buttonBorderRadius: 10
|
||||
}
|
||||
)
|
||||
.then((result: any) => {
|
||||
console.log('then');
|
||||
.then(function (result: any) {
|
||||
console.log('you at least try?')
|
||||
console.log(result);
|
||||
if (result?.access_token) {
|
||||
handleLogin(result.access_token);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
setShowButton(false);
|
||||
}, 1000)
|
||||
}
|
||||
return result.handler();
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('Yandex auth error:', error);
|
||||
.then(function (data: any) {
|
||||
console.log('Сообщение с токеном: ', data);
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('Что-то пошло не так: ', error);
|
||||
});
|
||||
}, [isReady]);
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export function YandexLoginButton() {
|
||||
const clientId = 'b356a7ceac0f4c50a3b434220f86bce0';
|
||||
const redirectUri = encodeURIComponent('https://fallibly-desired-moonfish.cloudpub.ru/login/callback');
|
||||
|
||||
const authUrl = `https://oauth.yandex.ru/authorize?response_type=code&client_id=${clientId}&redirect_uri=${redirectUri}&force_confirm=yes`;
|
||||
|
||||
return (
|
||||
<a
|
||||
href={authUrl}
|
||||
className="yandex-auth-button"
|
||||
>
|
||||
Войти через Яндекс
|
||||
</a>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user