Implement register and login with Telegram
Add the concept of authentication methods that authenticate an account where using the telegram login widget is one such method. If a login is done with an authentication method that's not associated with any account the session ends up with the data from the authentication method in order to allow registering a new account with the authentication method. This has to be stored on the session as otherwise it wouldn't be possible to implement authentication methods such as OAuth2 that takes the user to a third-party site and then redirects the browser back.
This commit is contained in:
parent
2d6bcebc5a
commit
aaa2faffb1
14 changed files with 357 additions and 8 deletions
20
shared/types/telegram.ts
Normal file
20
shared/types/telegram.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
import { z } from "zod/v4-mini";
|
||||
|
||||
export const telegramAuthDataSchema = z.catchall(
|
||||
z.object({
|
||||
// These fields are pure speculation as the actual API is undocumented.
|
||||
auth_date: z.number(),
|
||||
first_name: z.optional(z.string()),
|
||||
hash: z.string(),
|
||||
id: z.number(),
|
||||
last_name: z.optional(z.string()),
|
||||
photo_url: z.optional(z.string()),
|
||||
username: z.optional(z.string()),
|
||||
}),
|
||||
z.union([z.string(), z.number()]),
|
||||
);
|
||||
export type TelegramAuthData = z.infer<typeof telegramAuthDataSchema>;
|
Loading…
Add table
Add a link
Reference in a new issue