Skip to content

Commit

Permalink
fix: add callback to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Jul 4, 2024
1 parent cfa8d9d commit 38137ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion apps/staking/.env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ FAUCET_WALLET_PRIVATE_KEY=
NEXT_PUBLIC_ENV_FLAG= pick from dev, qa, stg, prd
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
TELEGRAM_BOT_TOKEN=
TELEGRAM_BOT_TOKEN=
NEXTAUTH_SECRET=
2 changes: 1 addition & 1 deletion packages/auth/components/DiscordAuthButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const DiscordAuthButton = forwardRef<HTMLButtonElement, DiscordAuthButton

const handleClick = () => {
if (!isConnected) {
signIn('discord');
signIn('discord', { callbackUrl: window.location.href });
} else {
signOut();
}
Expand Down
31 changes: 18 additions & 13 deletions packages/auth/components/TelegramAuthButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use client';

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

type TelegramAuthButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
csrfToken: string;
Expand All @@ -13,12 +16,14 @@ export const TelegramAuthButton = forwardRef<HTMLButtonElement, TelegramAuthButt
const { data, status } = useSession();

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

console.log(data);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const handleClick = (data: any) => {
if (!isConnected) {
signIn('telegram', { callbackUrl: '/faucet' }, data);
signIn('telegram', { callbackUrl: window.location.href }, data);
} else {
signOut();
}
Expand All @@ -27,19 +32,19 @@ export const TelegramAuthButton = forwardRef<HTMLButtonElement, TelegramAuthButt
return (
<>
<input name="csrfToken" type="hidden" defaultValue={csrfToken} />
<LoginButton botUsername="session_testnet_bot" onAuthCallback={handleClick} />
<div className="hidden">
<LoginButton botUsername="session_testnet_bot" />
</div>
<Button
onClick={handleClick}
data-testid={ButtonDataTestId.TELEGRAM_AUTH}
ref={ref}
{...props}
>
<TelegramIcon className="h-4 w-4" />
{isConnected ? username ?? 'Connected' : 'Connect Telegram'}
</Button>
</>
);
}
);
{
/* <Button
onClick={handleClick}
data-testid={ButtonDataTestId.DISCORD_AUTH}
ref={ref}
{...props}
>
<TelegramIcon className="h-4 w-4" />
{isConnected ? username ?? 'Connected' : 'Connect Discord'}
</Button> */
}

0 comments on commit 38137ef

Please sign in to comment.