Skip to content

Commit 6168706

Browse files
committed
feat: connect tg
1 parent f3488aa commit 6168706

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

pages/api/auth/telegram-callback.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ export default async function handler(
55
req: NextApiRequest,
66
res: NextApiResponse,
77
) {
8-
const { error, token } = req.query
8+
const { username = '', error = '', token } = req.query
99
return res.redirect(
10-
`${HOME_URL}/connect-telegram?token=${token}&error=${error}&done=true`,
10+
`${HOME_URL}/connect-telegram?token=${token}&done=true${
11+
error ? `&error=${error}` : ''
12+
}${username ? `&username=${username}` : ''}`,
1113
)
1214
}

pages/connect-telegram.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import { HOME_URL } from '~envs'
1010
import { useAuthStore, useProfileStore } from '~store'
1111

1212
export const getServerSideProps: GetServerSideProps = async (ctx) => {
13-
const { code, error = '', done } = ctx.query
13+
const { username = '', code, error = '', done } = ctx.query
1414

15-
if (!code)
15+
if (!code && !done)
1616
return {
1717
notFound: true,
1818
}
1919

2020
return {
2121
props: {
22+
username,
2223
code,
2324
error: decodeURIComponent(error as string),
2425
done: !!done,
@@ -30,10 +31,12 @@ export default function ConnectTelegram({
3031
code,
3132
error,
3233
done,
34+
username,
3335
}: {
3436
code?: string
3537
error?: string
3638
done: boolean
39+
username: string
3740
}) {
3841
const isLoading = useAuthStore((s) => s.isLoadingSession)
3942
const profile = useProfileStore((s) => s.me)
@@ -68,13 +71,18 @@ export default function ConnectTelegram({
6871
“{error}”
6972
</div>
7073
</div>
71-
) : hasTelegramAccount && done ? (
74+
) : hasTelegramAccount && username && done ? (
7275
<div className="py-8 px-8 mx-auto md:px-16 md:max-w-2xl">
7376
<div className="text-2xl font-black text-center md:text-3xl">
7477
<span className="uppercase text-mochi-gradient">
75-
Your Telegram is linked! You can close this window
78+
Your Telegram <span className="font-mono">@{username}</span>{' '}
79+
is linked! You can close this window
7680
</span>{' '}
7781
82+
<p className="mt-4 text-sm uppercase md:text-base">
83+
To connect with a different account, please disconnet the
84+
mochi.gg app via the Telegram and try again.
85+
</p>
7886
</div>
7987
</div>
8088
) : (

store/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const useAuthStore = create<State>((set, get) => ({
4747
.get('/profiles/me')
4848
.badRequest(logout)
4949
.unauthorized(logout)
50+
.internalError(logout)
5051
.res((res) => {
5152
set({ isLoadingSession: false })
5253
// if the code makes it here means the token is valid

0 commit comments

Comments
 (0)