45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
/* eslint-disable promise/prefer-await-to-then */
|
|
'use client';
|
|
import { getTelegramUser } from '@/mocks/get-telegram-user';
|
|
import { signIn, useSession } from 'next-auth/react';
|
|
import { useTheme } from 'next-themes';
|
|
import { redirect } from 'next/navigation';
|
|
import { useEffect } from 'react';
|
|
|
|
export default function Auth() {
|
|
const { data: session, status } = useSession();
|
|
useTheme();
|
|
|
|
useEffect(() => {
|
|
if (status === 'authenticated') {
|
|
redirect('/profile');
|
|
}
|
|
|
|
if (status === 'unauthenticated' && process.env.NODE_ENV === 'development') {
|
|
getTelegramUser().then((user) => {
|
|
signIn('telegram', {
|
|
callbackUrl: '/profile',
|
|
redirect: false,
|
|
telegramId: String(user?.id),
|
|
});
|
|
});
|
|
}
|
|
}, [status]);
|
|
|
|
if (status === 'loading') {
|
|
return <div>Loading Browser Auth...</div>;
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{session ? (
|
|
<div>
|
|
Browser Hello, {JSON.stringify(session)} <br />
|
|
</div>
|
|
) : (
|
|
<div>Not authenticated</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|