UNPKG

@shogun-sdk/accounts

Version:

Shogun with Turnkey: configs, encryption, authentication with Telegram/Turnkey OIDC, etc.

40 lines 1.31 kB
import { AuthDataValidator, objectToAuthDataMap } from '@telegram-auth/server'; const ONE_MINUTE_IN_SECONDS = 60; export async function validateLogin(params, botToken) { const validator = new AuthDataValidator({ botToken }); try { // Check if auth_date is older than 1 minute const currentTimestamp = Math.floor(Date.now() / 1000); const authDate = Number(params.auth_date); if (currentTimestamp - authDate > ONE_MINUTE_IN_SECONDS) { return { success: false, error: 'Authentication data is expired (older than 1 minute)', }; } const data = objectToAuthDataMap(params); const user = await validator.validate(data); if (user) { return { success: true, user: { ...user, hash: params.hash, }, }; } else { return { success: false, user: null, }; } } catch (error) { return { success: false, // Changed to false since this is an error case error: error instanceof Error ? error.message : 'Unknown Error', }; } } //# sourceMappingURL=telegram.js.map