Skip to content

Commit

Permalink
fix: test real button
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Jul 4, 2024
1 parent 702e33b commit a664418
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/auth/components/TelegramAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
'use client';

import { Button } from '@session/ui/ui/button';
import { LoginButton } from '@telegram-auth/react';
import { forwardRef, useRef } from 'react';
import { TelegramIcon } from '../icons/TelegramIcon';
import { forwardRef } from 'react';
import { signIn, signOut, useSession } from '../lib/client';
import { ButtonDataTestId } from '../testing/data-test-ids';

type TelegramAuthButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
csrfToken: string;
};

export const TelegramAuthButton = forwardRef<HTMLButtonElement, TelegramAuthButtonProps>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
({ csrfToken, ...props }, ref) => {
const { data, status } = useSession();
const buttonContainerRef = useRef<HTMLDivElement>(null);

const isConnected = status === 'authenticated';
const username = data?.user?.name;

console.log(data);

const handleButtonClick = () => {
const button = buttonContainerRef.current?.querySelector('button');
button?.click();
};
console.log('username', username);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleClick = (data: any) => {
Expand All @@ -38,18 +32,18 @@ export const TelegramAuthButton = forwardRef<HTMLButtonElement, TelegramAuthButt
return (
<>
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />
<div className="hidden">
<LoginButton botUsername="session_testnet_bot" onAuthCallback={handleClick} />
</div>
<Button
{/* <div className="hidden"> */}
<LoginButton botUsername="session_testnet_bot" onAuthCallback={handleClick} />
{/* </div> */}
{/* <Button
onClick={handleButtonClick}
data-testid={ButtonDataTestId.TELEGRAM_AUTH}
ref={ref}
{...props}
>
<TelegramIcon className="h-4 w-4" />
{isConnected ? username ?? 'Connected' : 'Connect Telegram'}
</Button>
</Button> */}
</>
);
}
Expand Down

0 comments on commit a664418

Please sign in to comment.