Skip to content

Commit

Permalink
feat: add telegram and discord connect buttons to faucet
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Jul 4, 2024
1 parent 7ec1d69 commit cfa8d9d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
5 changes: 4 additions & 1 deletion apps/staking/.env.local.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
NEXT_PUBLIC_SENT_STAKING_API_URL=
FAUCET_WALLET_PRIVATE_KEY=
NEXT_PUBLIC_ENV_FLAG= pick from dev, qa, stg, prd
NEXT_PUBLIC_ENV_FLAG= pick from dev, qa, stg, prd
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
TELEGRAM_BOT_TOKEN=
31 changes: 31 additions & 0 deletions apps/staking/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createAuthHandler } from '@session/auth/api';
import { DiscordProvider, handleDiscordSession } from '@session/auth/providers/discord';
import { TelegramProvider } from '@session/auth/providers/telegram';

const discordClientId = process.env.DISCORD_CLIENT_ID;
const discordClientSecret = process.env.DISCORD_CLIENT_SECRET;
const telegramBotToken = process.env.TELEGRAM_BOT_TOKEN;

if (!discordClientId || !discordClientSecret) {
throw new Error('Discord client ID and client secret must be provided');
}

if (!telegramBotToken) {
throw new Error('Telegram bot token must be provided');
}

export const { GET, POST } = createAuthHandler({
providers: [
DiscordProvider({
clientId: discordClientId,
clientSecret: discordClientSecret,
}),
TelegramProvider({ botToken: telegramBotToken }),
],
callbacks: {
async session({ session, token }) {
handleDiscordSession({ session, token });
return session;
},
},
});
12 changes: 12 additions & 0 deletions apps/staking/app/faucet/AuthModule.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useSession } from '@session/auth/client';

export const AuthModule = () => {
const { data, status } = useSession();

console.log(data);

/** @ts-expect-error -- Workaround to get id */
const discordId = data?.user?.discordId;

return <pre>{discordId}</pre>;
};
21 changes: 20 additions & 1 deletion apps/staking/app/faucet/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
'use client';
import { NextAuthProvider } from '@session/auth/client';
import { DiscordAuthButton } from '@session/auth/components/DiscordAuthButton';
import { TelegramAuthButton } from '@session/auth/components/TelegramAuthButton';
import { AuthModule } from './AuthModule';

export default function FaucetPage() {
return <div className="flex justify-center p-4 align-middle">{/* <FaucetModule /> */}</div>;
return (
<NextAuthProvider>
<div className="flex justify-center p-4 align-middle">
<AuthModule />
<DiscordAuthButton />
<TelegramButton />
</div>
</NextAuthProvider>
);
}

async function TelegramButton() {
const csrfToken = '';
return <TelegramAuthButton csrfToken={csrfToken} />;
}
8 changes: 7 additions & 1 deletion apps/staking/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export default function LandingPage() {
</div>
</div>
<div className="flex max-w-[50vh] items-center justify-center align-middle lg:max-w-full">
<Image src="/images/cube.png" alt={dictionary('heroImageAlt')} height={1024} width={1024} />
<Image
src="/images/cube.png"
alt={dictionary('heroImageAlt')}
height={1024}
width={1024}
priority
/>
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions apps/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@session/contracts": "workspace:*",
"@session/sent-staking-js": "workspace:*",
"@session/ui": "workspace:*",
"@session/auth": "workspace:*",
"@session/util": "workspace:*",
"@session/wallet": "workspace:*",
"@tanstack/react-query": "^5.32.1",
Expand Down

0 comments on commit cfa8d9d

Please sign in to comment.