@telegram-login-ultimate/react 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -28
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +34 -48
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -8
- package/dist/cjs/hooks/index.js +0 -3
- package/dist/cjs/hooks/index.js.map +0 -1
- package/dist/cjs/hooks/use-telegram-login.js +0 -3
- package/dist/cjs/hooks/use-telegram-login.js.map +0 -1
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/hooks/index.js +0 -3
- package/dist/esm/hooks/index.js.map +0 -1
- package/dist/esm/hooks/use-telegram-login.js +0 -3
- package/dist/esm/hooks/use-telegram-login.js.map +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,32 +14,6 @@ yarn add @telegram-login-ultimate/react
|
|
|
14
14
|
pnpm add @telegram-login-ultimate/react
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Documentation
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- Simple usage - import hook and use
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
```jsx
|
|
25
|
-
import React from 'react';
|
|
26
|
-
import ReactDOM from 'react-dom';
|
|
27
|
-
import { useTelegramLogin } from '@telegram-login-ultimate/react';
|
|
28
|
-
|
|
29
|
-
const App = () => {
|
|
30
|
-
const [openPopup, { isPending }] = useTelegramLogin({
|
|
31
|
-
botId: <your_bot_id>,
|
|
32
|
-
onSuccess: (user) => handleSuccess(user),
|
|
33
|
-
onFail: () => handleFail(),
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<button disabled={isPending} onClick={openPopup}>
|
|
38
|
-
{isPending ? 'Popup opened' : 'Open popup'}
|
|
39
|
-
</button>
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const root = ReactDOM.createRoot(document.getElementById('root'));
|
|
44
|
-
root.render(<App/>);
|
|
45
|
-
```
|
|
19
|
+
You can find documentation [here](https://telegram-login-ultimate.vercel.app/packages/react.html)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LoginOptions, TelegramLoginClient, TelegramLoginClient as TelegramLoginClient$1, TelegramLoginClientOptions, TelegramUserData, isAuthenticationError } from "@telegram-login-ultimate/core";
|
|
2
|
+
|
|
3
|
+
//#region src/hook.d.ts
|
|
4
|
+
type UseTelegramLoginOptions = LoginOptions;
|
|
5
|
+
interface UseTelegramLoginReturn {
|
|
6
|
+
/**
|
|
7
|
+
* Flag indicating whether the login process is pending.
|
|
8
|
+
*/
|
|
9
|
+
isPending: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Function to start the login process.
|
|
12
|
+
*/
|
|
13
|
+
start: () => void;
|
|
14
|
+
}
|
|
15
|
+
declare const useTelegramLogin: ({
|
|
16
|
+
botId,
|
|
17
|
+
onError,
|
|
18
|
+
onSuccess,
|
|
19
|
+
onStart
|
|
20
|
+
}: UseTelegramLoginOptions) => UseTelegramLoginReturn;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/provider.d.ts
|
|
23
|
+
interface TelegramLoginProviderProps {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Telegram login client instance.
|
|
27
|
+
*/
|
|
28
|
+
client: TelegramLoginClient$1;
|
|
29
|
+
}
|
|
30
|
+
declare const TelegramLoginProvider: ({
|
|
31
|
+
client,
|
|
32
|
+
children
|
|
33
|
+
}: TelegramLoginProviderProps) => React.ReactElement;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { TelegramLoginClient, type TelegramLoginClientOptions, TelegramLoginProvider, type TelegramLoginProviderProps, type TelegramUserData, type UseTelegramLoginOptions, type UseTelegramLoginReturn, type isAuthenticationError, useTelegramLogin };
|
|
36
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,50 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Unique identifier for the user.
|
|
16
|
-
*/
|
|
17
|
-
id: number;
|
|
18
|
-
/**
|
|
19
|
-
* User's last name, if available.
|
|
20
|
-
*/
|
|
21
|
-
last_name?: string;
|
|
22
|
-
/**
|
|
23
|
-
* URL of the user's profile photo, if available.
|
|
24
|
-
*/
|
|
25
|
-
photo_url?: string;
|
|
26
|
-
/**
|
|
27
|
-
* User's username, if available.
|
|
28
|
-
*/
|
|
29
|
-
username?: string;
|
|
1
|
+
import { LoginOptions, TelegramLoginClient, TelegramLoginClient as TelegramLoginClient$1, TelegramLoginClientOptions, TelegramUserData, isAuthenticationError } from "@telegram-login-ultimate/core";
|
|
2
|
+
|
|
3
|
+
//#region src/hook.d.ts
|
|
4
|
+
type UseTelegramLoginOptions = LoginOptions;
|
|
5
|
+
interface UseTelegramLoginReturn {
|
|
6
|
+
/**
|
|
7
|
+
* Flag indicating whether the login process is pending.
|
|
8
|
+
*/
|
|
9
|
+
isPending: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Function to start the login process.
|
|
12
|
+
*/
|
|
13
|
+
start: () => void;
|
|
30
14
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
declare const useTelegramLogin: ({
|
|
16
|
+
botId,
|
|
17
|
+
onError,
|
|
18
|
+
onSuccess,
|
|
19
|
+
onStart
|
|
20
|
+
}: UseTelegramLoginOptions) => UseTelegramLoginReturn;
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/provider.d.ts
|
|
23
|
+
interface TelegramLoginProviderProps {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Telegram login client instance.
|
|
27
|
+
*/
|
|
28
|
+
client: TelegramLoginClient$1;
|
|
45
29
|
}
|
|
46
|
-
declare const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
declare const TelegramLoginProvider: ({
|
|
31
|
+
client,
|
|
32
|
+
children
|
|
33
|
+
}: TelegramLoginProviderProps) => React.ReactElement;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { TelegramLoginClient, type TelegramLoginClientOptions, TelegramLoginProvider, type TelegramLoginProviderProps, type TelegramUserData, type UseTelegramLoginOptions, type UseTelegramLoginReturn, type isAuthenticationError, useTelegramLogin };
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);let l=require(`react/jsx-runtime`);l=s(l);let u=require(`@telegram-login-ultimate/core`);u=s(u);const d=(0,c.createContext)(void 0),f=({botId:e,onError:t,onSuccess:n,onStart:r})=>{let[i,a]=(0,c.useState)(!1),o=(0,c.useContext)(d);if(!o)throw Error(`useTelegramLogin must be used within a TelegramLoginProvider`);let s=()=>{a(!0),r?.()},l=e=>{a(!1),t?.(e)},u=e=>{a(!1),n?.(e)};return{start:()=>{o.login({botId:e,onError:l,onSuccess:u,onStart:s})},isPending:i}},p=({client:e,children:t})=>(0,l.jsx)(d.Provider,{value:e,children:t});Object.defineProperty(exports,`TelegramLoginClient`,{enumerable:!0,get:function(){return u.TelegramLoginClient}}),exports.TelegramLoginProvider=p,exports.useTelegramLogin=f;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/context.ts","../src/hook.ts","../src/provider.tsx"],"sourcesContent":["import type { TelegramLoginClient } from '@telegram-login-ultimate/core'\n\nimport { createContext } from 'react'\n\nexport const TelegramLoginContext = createContext<\n TelegramLoginClient | undefined\n>(undefined)\n","import type {\n LoginOptions,\n TelegramUserData,\n} from '@telegram-login-ultimate/core'\n\nimport { useContext, useState } from 'react'\n\nimport { TelegramLoginContext } from './context'\n\nexport type UseTelegramLoginOptions = LoginOptions\n\nexport interface UseTelegramLoginReturn {\n /**\n * Flag indicating whether the login process is pending.\n */\n isPending: boolean\n\n /**\n * Function to start the login process.\n */\n start: () => void\n}\n\nexport const useTelegramLogin = ({\n botId,\n onError,\n onSuccess,\n onStart,\n}: UseTelegramLoginOptions): UseTelegramLoginReturn => {\n const [isPending, setIsPending] = useState(false)\n const client = useContext(TelegramLoginContext)\n\n if (!client) {\n throw new Error(\n 'useTelegramLogin must be used within a TelegramLoginProvider',\n )\n }\n\n const handleStart = (): void => {\n setIsPending(true)\n onStart?.()\n }\n\n const handleError = (error: unknown): void => {\n setIsPending(false)\n onError?.(error)\n }\n\n const handleSuccess = (data: TelegramUserData): void => {\n setIsPending(false)\n onSuccess?.(data)\n }\n\n const start = (): void => {\n client.login({\n botId,\n onError: handleError,\n onSuccess: handleSuccess,\n onStart: handleStart,\n })\n }\n\n return { start, isPending } as const\n}\n","import type { TelegramLoginClient } from '@telegram-login-ultimate/core'\n\nimport { TelegramLoginContext } from './context'\n\nexport interface TelegramLoginProviderProps {\n children: React.ReactNode\n\n /**\n * Telegram login client instance.\n */\n client: TelegramLoginClient\n}\n\nexport const TelegramLoginProvider = ({\n client,\n children,\n}: TelegramLoginProviderProps): React.ReactElement => {\n return (\n <TelegramLoginContext.Provider value={client}>\n {children}\n </TelegramLoginContext.Provider>\n )\n}\n"],"mappings":"4lBAIA,MAAa,GAAA,EAAA,EAAA,eAEX,IAAA,GAAU,CCiBC,GAAoB,CAC/B,QACA,UACA,YACA,aACqD,CACrD,GAAM,CAAC,EAAW,IAAA,EAAA,EAAA,UAAyB,GAAM,CAC3C,GAAA,EAAA,EAAA,YAAoB,EAAqB,CAE/C,GAAI,CAAC,EACH,MAAU,MACR,+DACD,CAGH,IAAM,MAA0B,CAC9B,EAAa,GAAK,CAClB,KAAW,EAGP,EAAe,GAAyB,CAC5C,EAAa,GAAM,CACnB,IAAU,EAAM,EAGZ,EAAiB,GAAiC,CACtD,EAAa,GAAM,CACnB,IAAY,EAAK,EAYnB,MAAO,CAAE,UATiB,CACxB,EAAO,MAAM,CACX,QACA,QAAS,EACT,UAAW,EACX,QAAS,EACV,CAAC,EAGY,YAAW,ECjDhB,GAAyB,CACpC,SACA,eAGE,EAAA,EAAA,KAAC,EAAqB,SAAA,CAAS,MAAO,EACnC,YAC6B"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createContext as e,useContext as t,useState as n}from"react";import{jsx as r}from"react/jsx-runtime";import{TelegramLoginClient as i}from"@telegram-login-ultimate/core";const a=e(void 0),o=({botId:e,onError:r,onSuccess:i,onStart:o})=>{let[s,c]=n(!1),l=t(a);if(!l)throw Error(`useTelegramLogin must be used within a TelegramLoginProvider`);let u=()=>{c(!0),o?.()},d=e=>{c(!1),r?.(e)},f=e=>{c(!1),i?.(e)};return{start:()=>{l.login({botId:e,onError:d,onSuccess:f,onStart:u})},isPending:s}},s=({client:e,children:t})=>r(a.Provider,{value:e,children:t});export{i as TelegramLoginClient,s as TelegramLoginProvider,o as useTelegramLogin};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/context.ts","../src/hook.ts","../src/provider.tsx"],"sourcesContent":["import type { TelegramLoginClient } from '@telegram-login-ultimate/core'\n\nimport { createContext } from 'react'\n\nexport const TelegramLoginContext = createContext<\n TelegramLoginClient | undefined\n>(undefined)\n","import type {\n LoginOptions,\n TelegramUserData,\n} from '@telegram-login-ultimate/core'\n\nimport { useContext, useState } from 'react'\n\nimport { TelegramLoginContext } from './context'\n\nexport type UseTelegramLoginOptions = LoginOptions\n\nexport interface UseTelegramLoginReturn {\n /**\n * Flag indicating whether the login process is pending.\n */\n isPending: boolean\n\n /**\n * Function to start the login process.\n */\n start: () => void\n}\n\nexport const useTelegramLogin = ({\n botId,\n onError,\n onSuccess,\n onStart,\n}: UseTelegramLoginOptions): UseTelegramLoginReturn => {\n const [isPending, setIsPending] = useState(false)\n const client = useContext(TelegramLoginContext)\n\n if (!client) {\n throw new Error(\n 'useTelegramLogin must be used within a TelegramLoginProvider',\n )\n }\n\n const handleStart = (): void => {\n setIsPending(true)\n onStart?.()\n }\n\n const handleError = (error: unknown): void => {\n setIsPending(false)\n onError?.(error)\n }\n\n const handleSuccess = (data: TelegramUserData): void => {\n setIsPending(false)\n onSuccess?.(data)\n }\n\n const start = (): void => {\n client.login({\n botId,\n onError: handleError,\n onSuccess: handleSuccess,\n onStart: handleStart,\n })\n }\n\n return { start, isPending } as const\n}\n","import type { TelegramLoginClient } from '@telegram-login-ultimate/core'\n\nimport { TelegramLoginContext } from './context'\n\nexport interface TelegramLoginProviderProps {\n children: React.ReactNode\n\n /**\n * Telegram login client instance.\n */\n client: TelegramLoginClient\n}\n\nexport const TelegramLoginProvider = ({\n client,\n children,\n}: TelegramLoginProviderProps): React.ReactElement => {\n return (\n <TelegramLoginContext.Provider value={client}>\n {children}\n </TelegramLoginContext.Provider>\n )\n}\n"],"mappings":"gLAIA,MAAa,EAAuB,EAElC,IAAA,GAAU,CCiBC,GAAoB,CAC/B,QACA,UACA,YACA,aACqD,CACrD,GAAM,CAAC,EAAW,GAAgB,EAAS,GAAM,CAC3C,EAAS,EAAW,EAAqB,CAE/C,GAAI,CAAC,EACH,MAAU,MACR,+DACD,CAGH,IAAM,MAA0B,CAC9B,EAAa,GAAK,CAClB,KAAW,EAGP,EAAe,GAAyB,CAC5C,EAAa,GAAM,CACnB,IAAU,EAAM,EAGZ,EAAiB,GAAiC,CACtD,EAAa,GAAM,CACnB,IAAY,EAAK,EAYnB,MAAO,CAAE,UATiB,CACxB,EAAO,MAAM,CACX,QACA,QAAS,EACT,UAAW,EACX,QAAS,EACV,CAAC,EAGY,YAAW,ECjDhB,GAAyB,CACpC,SACA,cAGE,EAAC,EAAqB,SAAA,CAAS,MAAO,EACnC,YAC6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telegram-login-ultimate/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Ultimate tool for working with Telegram login API with TypeScript support in your React application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"homepage": "https://github.com/notcodev/telegram-login-ultimate",
|
|
21
21
|
"bugs": "https://github.com/notcodev/telegram-login-ultimate/issues",
|
|
22
|
-
"main": "dist/
|
|
23
|
-
"module": "dist/
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"module": "dist/index.mjs",
|
|
24
24
|
"types": "dist/index.d.ts",
|
|
25
25
|
"keywords": [
|
|
26
26
|
"telegram",
|
|
@@ -38,17 +38,18 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@siberiacancode/builder": "^1.3.11",
|
|
42
41
|
"@types/react": "^19.1.8",
|
|
43
42
|
"@types/react-dom": "^19.1.6",
|
|
44
|
-
"@vitejs/plugin-react": "^
|
|
43
|
+
"@vitejs/plugin-react": "^5.0.2",
|
|
45
44
|
"react": "^19.1.0",
|
|
46
45
|
"react-dom": "^19.1.0",
|
|
47
|
-
"
|
|
48
|
-
|
|
46
|
+
"vite": "^7.1.4"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@telegram-login-ultimate/core": "2.0.0"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
|
-
"build": "
|
|
52
|
+
"build": "tsdown",
|
|
52
53
|
"lint": "eslint . --ext ts --ext tsx --no-error-on-unmatched-pattern --fix",
|
|
53
54
|
"dev": "cd ./playground && vite"
|
|
54
55
|
}
|
package/dist/cjs/hooks/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @telegram-login-ultimate/react v1.1.2 */
|
|
2
|
-
"use strict";var t=require("react");function r(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function e(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function n(){n=function(){return r};var t,r={},e=Object.prototype,o=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function s(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{s({},"")}catch(t){s=function(t,r,e){return t[r]=e}}function h(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),u=new F(n||[]);return i(a,"_invoke",{value:S(t,e,u)}),a}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var p="suspendedStart",d="suspendedYield",v="executing",y="completed",g={};function m(){}function w(){}function b(){}var x={};s(x,u,(function(){return this}));var L=Object.getPrototypeOf,E=L&&L(L(k([])));E&&E!==e&&o.call(E,u)&&(x=E);var _=b.prototype=m.prototype=Object.create(x);function O(t){["next","throw","return"].forEach((function(r){s(t,r,(function(t){return this._invoke(r,t)}))}))}function j(t,r){function e(n,i,a,u){var c=f(t[n],t,i);if("throw"!==c.type){var l=c.arg,s=l.value;return s&&"object"==typeof s&&o.call(s,"__await")?r.resolve(s.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(s).then((function(t){l.value=t,a(l)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=I(u,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var l=f(r,e,n);if("normal"===l.type){if(o=n.done?y:d,l.arg===g)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(o=y,n.method="throw",n.arg=l.arg)}}}function I(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,I(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=f(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function T(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function P(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function F(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function k(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(_,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=s(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,l,"GeneratorFunction")),t.prototype=Object.create(_),t},r.awrap=function(t){return{__await:t}},O(j.prototype),s(j.prototype,c,(function(){return this})),r.AsyncIterator=j,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new j(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(_),s(_,l,"Generator"),s(_,u,(function(){return this})),s(_,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=k,F.prototype={constructor:F,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),l=o.call(a,"finallyLoc");if(c&&l){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),g},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),P(e),g}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;P(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:k(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),g}},r}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(e=e.call(t)).next,0===r);else for(;!(c=(n=i.call(e)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,e)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var i="https://oauth.telegram.org";exports.useTelegramLogin=function(r){var a=r.botId,u=r.onFail,c=r.onSuccess,l=o(t.useState(!1),2),s=l[0],h=l[1],f=t.useRef({});return[function(){var t=Math.max(0,(screen.width-550)/2)+screen.availWidth,r=Math.max(0,(screen.height-470)/2)+screen.availHeight,o=i+"/auth?bot_id="+encodeURIComponent(a)+"&origin="+encodeURIComponent(location.origin||location.protocol+"//"+location.hostname)+"&return_to="+encodeURIComponent(location.href),l=window.open(o,"telegram_oauth_bot"+a,"width=550,height=470,left="+t+",top="+r+",status=0,location=0,menubar=0,toolbar=0");function s(t){if(t.source===f.current[a].window&&a in f.current){var r=JSON.parse(t.data);"auth_result"===r.event&&p(r.result)}}function p(t){a in f.current&&(f.current[a].authFinished||(t?null==c||c(t):null==u||u(),h(!1),f.current[a].authFinished=!0,window.removeEventListener("message",s)))}function d(){var t;return t=n().mark((function t(r){var e,o,a;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=i+"/auth/get?bot_id="+encodeURIComponent(r.botId),o={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"},t.next=4,fetch(e,{method:"POST",headers:o,credentials:"include"});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t)})),d=function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))},d.apply(this,arguments)}f.current[a]={window:l,authFinished:!1},l&&(h(!0),window.addEventListener("message",s),l.focus(),function t(r){if(!(r in f.current))return;var e=f.current[r];if(!e.window||e.window.closed)return function(t){return d.apply(this,arguments)}({botId:r}).then((function(t){p("user"in t&&t.user)})).catch((function(){h(!1),null==u||u()}));setTimeout((function(){return t(r)}),100)}(a))},{isPending:s}]};
|
|
3
|
-
//# sourceMappingURL=use-telegram-login.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-telegram-login.js","sources":["../../../src/hooks/use-telegram-login.ts"],"sourcesContent":["import { useRef, useState } from 'react'\n\nconst POPUP_WIDTH = 550\nconst POPUP_HEIGHT = 470\nconst POPUP_ORIGIN = 'https://oauth.telegram.org'\n\nexport interface TelegramLoginData {\n /**\n * Unix timestamp indicating when the authentication occurred.\n */\n auth_date: number\n /**\n * User's first name.\n */\n first_name: string\n /**\n * Data hash for verification of the authentication data integrity.\n */\n hash: string\n /**\n * Unique identifier for the user.\n */\n id: number\n /**\n * User's last name, if available.\n */\n last_name?: string\n /**\n * URL of the user's profile photo, if available.\n */\n photo_url?: string\n /**\n * User's username, if available.\n */\n username?: string\n}\n\nexport interface UseTelegramLoginOptions {\n /**\n * The unique identifier of the Telegram bot. You can obtain it from the https://t.me/username_to_id_bot.\n */\n botId: number\n\n /**\n * Optional callback function that will be called when the login process completes successfully.\n * @param {TelegramUserData} data - The authentication data returned from Telegram.\n */\n onSuccess?: (data: TelegramLoginData) => unknown\n\n /**\n * Optional callback function that will be called if an error occurs during the login process.\n */\n onFail?: () => unknown\n}\n\nexport const useTelegramLogin = ({\n botId,\n onFail,\n onSuccess,\n}: UseTelegramLoginOptions) => {\n const [isPending, setIsPending] = useState(false)\n const popups = useRef<\n Record<number, { window: Window | null; authFinished: boolean }>\n >({})\n\n return [\n () => {\n const width = POPUP_WIDTH\n const height = POPUP_HEIGHT\n const left = Math.max(0, (screen.width - width) / 2) + screen.availWidth\n const top = Math.max(0, (screen.height - height) / 2) + screen.availHeight\n\n const popupUrl =\n POPUP_ORIGIN +\n '/auth?bot_id=' +\n encodeURIComponent(botId) +\n '&origin=' +\n encodeURIComponent(\n location.origin || location.protocol + '//' + location.hostname,\n ) +\n '&return_to=' +\n encodeURIComponent(location.href)\n\n const popup = window.open(\n popupUrl,\n 'telegram_oauth_bot' + botId,\n 'width=' +\n width +\n ',height=' +\n height +\n ',left=' +\n left +\n ',top=' +\n top +\n ',status=0,location=0,menubar=0,toolbar=0',\n )\n\n popups.current[botId] = {\n window: popup,\n authFinished: false,\n }\n\n if (popup) {\n setIsPending(true)\n window.addEventListener('message', onMessage)\n popup.focus()\n checkClose(botId)\n }\n\n function onMessage(event: MessageEvent<string>) {\n if (event.source !== popups.current[botId].window) return\n if (!(botId in popups.current)) return\n\n const data: { event: string; result: TelegramLoginData | false } =\n JSON.parse(event.data)\n\n if (data.event === 'auth_result') {\n onAuth(data.result)\n }\n }\n\n function onAuth(authData: TelegramLoginData | false) {\n if (!(botId in popups.current)) return\n if (popups.current[botId].authFinished) return\n\n if (authData) {\n onSuccess?.(authData)\n } else {\n onFail?.()\n }\n\n setIsPending(false)\n popups.current[botId].authFinished = true\n window.removeEventListener('message', onMessage)\n }\n\n function checkClose(botId: number) {\n if (!(botId in popups.current)) return\n\n const currentPopup = popups.current[botId]\n\n if (!currentPopup.window || currentPopup.window.closed) {\n return getAuthData({ botId })\n .then((res) => {\n if ('user' in res) {\n onAuth(res.user)\n } else {\n onAuth(false)\n }\n })\n .catch(() => {\n setIsPending(false)\n onFail?.()\n })\n }\n\n setTimeout(() => checkClose(botId), 100)\n }\n\n async function getAuthData(options: { botId: number }): Promise<\n ({ user: TelegramLoginData } | { error: string }) & {\n html: string\n origin: string\n }\n > {\n const url =\n POPUP_ORIGIN +\n '/auth/get' +\n '?bot_id=' +\n encodeURIComponent(options.botId)\n\n const headers = {\n 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',\n 'X-Requested-With': 'XMLHttpRequest',\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n credentials: 'include',\n })\n\n return response.json()\n }\n },\n { isPending },\n ] as const\n}\n"],"names":["POPUP_ORIGIN","_ref","botId","onFail","onSuccess","_useState2","_slicedToArray","useState","isPending","setIsPending","popups","useRef","left","Math","max","screen","width","availWidth","top","height","availHeight","popupUrl","encodeURIComponent","location","origin","protocol","hostname","href","popup","window","open","onMessage","event","source","current","data","JSON","parse","onAuth","result","authData","authFinished","removeEventListener","_getAuthData","_regeneratorRuntime","mark","_callee","options","url","headers","response","wrap","_context","prev","next","fetch","method","credentials","sent","abrupt","json","stop","apply","this","arguments","addEventListener","focus","checkClose","currentPopup","closed","_x","getAuthData","then","res","user","setTimeout"],"mappings":";s+OAEA,IAEMA,EAAe,sDAmDW,SAAHC,GAIE,IAH7BC,EAAKD,EAALC,MACAC,EAAMF,EAANE,OACAC,EAASH,EAATG,UAEiDC,EAAAC,EAAfC,EAAAA,UAAS,GAAM,GAA1CC,EAASH,EAAA,GAAEI,EAAYJ,EAAA,GACxBK,EAASC,EAAAA,OAEb,IAEF,MAAO,CACL,WACE,IAEMC,EAAOC,KAAKC,IAAI,GAAIC,OAAOC,MAnEnB,KAmEoC,GAAKD,OAAOE,WACxDC,EAAML,KAAKC,IAAI,GAAIC,OAAOI,OAnEjB,KAmEoC,GAAKJ,OAAOK,YAEzDC,EACJrB,EACA,gBACAsB,mBAAmBpB,GACnB,WACAoB,mBACEC,SAASC,QAAUD,SAASE,SAAW,KAAOF,SAASG,UAEzD,cACAJ,mBAAmBC,SAASI,MAExBC,EAAQC,OAAOC,KACnBT,EACA,qBAAuBnB,EACvB,6BAKEU,EACA,QACAM,EACA,4CAeJ,SAASa,EAAUC,GACjB,GAAIA,EAAMC,SAAWvB,EAAOwB,QAAQhC,GAAO2B,QACrC3B,KAASQ,EAAOwB,QAAtB,CAEA,IAAMC,EACJC,KAAKC,MAAML,EAAMG,MAEA,gBAAfA,EAAKH,OACPM,EAAOH,EAAKI,OANkB,CAQlC,CAEA,SAASD,EAAOE,GACRtC,KAASQ,EAAOwB,UAClBxB,EAAOwB,QAAQhC,GAAOuC,eAEtBD,EACFpC,SAAAA,EAAYoC,GAEZrC,SAAAA,IAGFM,GAAa,GACbC,EAAOwB,QAAQhC,GAAOuC,cAAe,EACrCZ,OAAOa,oBAAoB,UAAWX,IACxC,CAyB0B,SAAAY,UAwBzB,SAxByBC,IAAAC,MAA1B,SAAAC,EAA2BC,GAA0B,IAAAC,EAAAC,EAAAC,EAAA,OAAAN,IAAAO,MAAA,SAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,KAAA,EAelD,OATKN,EACJhD,sBAGAsB,mBAAmByB,EAAQ7C,OAEvB+C,EAAU,CACd,eAAgB,mDAChB,mBAAoB,kBACrBG,EAAAE,KAAA,EAEsBC,MAAMP,EAAK,CAChCQ,OAAQ,OACRP,QAAAA,EACAQ,YAAa,YACb,KAAA,EAJY,OAARP,EAAQE,EAAAM,KAAAN,EAAAO,OAAA,SAMPT,EAASU,QAAM,KAAA,EAAA,IAAA,MAAA,OAAAR,EAAAS,OAAA,GAAAf,EAAA,IAvBEH,gLAwBzBA,EAAAmB,MAAAC,KAAAC,UAAA,CAtFDtD,EAAOwB,QAAQhC,GAAS,CACtB2B,OAAQD,EACRa,cAAc,GAGZb,IACFnB,GAAa,GACboB,OAAOoC,iBAAiB,UAAWlC,GACnCH,EAAMsC,QA+BR,SAASC,EAAWjE,GAClB,KAAMA,KAASQ,EAAOwB,SAAU,OAEhC,IAAMkC,EAAe1D,EAAOwB,QAAQhC,GAEpC,IAAKkE,EAAavC,QAAUuC,EAAavC,OAAOwC,OAC9C,OAeH,SAEyBC,GAAA,OAAA3B,EAAAmB,MAAAC,KAAAC,UAAA,CAjBfO,CAAY,CAAErE,MAAAA,IAClBsE,MAAK,SAACC,GAEHnC,EADE,SAAUmC,GACLA,EAAIC,KAIf,IAAE,OACK,WACLjE,GAAa,GACbN,SAAAA,GACF,IAGJwE,YAAW,WAAA,OAAMR,EAAWjE,EAAM,GAAE,IACtC,CAnDEiE,CAAWjE,GA8Ef,EACA,CAAEM,UAAAA,GAEN"}
|
package/dist/cjs/index.js
DELETED
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/esm/hooks/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* @license @telegram-login-ultimate/react v1.1.2 */
|
|
2
|
-
import{useState as t,useRef as r}from"react";function e(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function n(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function o(){o=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function h(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{h({},"")}catch(t){h=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),u=new F(n||[]);return i(a,"_invoke",{value:S(t,e,u)}),a}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",d="suspendedYield",y="executing",v="completed",g={};function m(){}function w(){}function b(){}var x={};h(x,u,(function(){return this}));var L=Object.getPrototypeOf,E=L&&L(L(k([])));E&&E!==e&&n.call(E,u)&&(x=E);var _=b.prototype=m.prototype=Object.create(x);function O(t){["next","throw","return"].forEach((function(r){h(t,r,(function(t){return this._invoke(r,t)}))}))}function j(t,r){function e(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&n.call(h,"__await")?r.resolve(h.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(h).then((function(t){l.value=t,a(l)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new r((function(r,o){e(t,n,r,o)}))}return o=o?o.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===y)throw Error("Generator is already running");if(o===v){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=I(u,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var l=f(r,e,n);if("normal"===l.type){if(o=n.done?v:d,l.arg===g)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(o=v,n.method="throw",n.arg=l.arg)}}}function I(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,I(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=f(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function T(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function F(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function k(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(_,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=h(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,h(t,l,"GeneratorFunction")),t.prototype=Object.create(_),t},r.awrap=function(t){return{__await:t}},O(j.prototype),h(j.prototype,c,(function(){return this})),r.AsyncIterator=j,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new j(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(_),h(_,l,"Generator"),h(_,u,(function(){return this})),h(_,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=k,F.prototype={constructor:F,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(c&&l){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),g},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),T(e),g}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;T(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:k(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),g}},r}function i(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,i,a,u=[],c=!0,l=!1;try{if(i=(e=e.call(t)).next,0===r);else for(;!(c=(n=i.call(e)).done)&&(u.push(n.value),u.length!==r);c=!0);}catch(t){l=!0,o=t}finally{try{if(!c&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(t,r)||function(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a="https://oauth.telegram.org",u=function(e){var u=e.botId,c=e.onFail,l=e.onSuccess,h=i(t(!1),2),s=h[0],f=h[1],p=r({});return[function(){var t=Math.max(0,(screen.width-550)/2)+screen.availWidth,r=Math.max(0,(screen.height-470)/2)+screen.availHeight,e=a+"/auth?bot_id="+encodeURIComponent(u)+"&origin="+encodeURIComponent(location.origin||location.protocol+"//"+location.hostname)+"&return_to="+encodeURIComponent(location.href),i=window.open(e,"telegram_oauth_bot"+u,"width=550,height=470,left="+t+",top="+r+",status=0,location=0,menubar=0,toolbar=0");function h(t){if(t.source===p.current[u].window&&u in p.current){var r=JSON.parse(t.data);"auth_result"===r.event&&s(r.result)}}function s(t){u in p.current&&(p.current[u].authFinished||(t?null==l||l(t):null==c||c(),f(!1),p.current[u].authFinished=!0,window.removeEventListener("message",h)))}function d(){var t;return t=o().mark((function t(r){var e,n,i;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=a+"/auth/get?bot_id="+encodeURIComponent(r.botId),n={"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","X-Requested-With":"XMLHttpRequest"},t.next=4,fetch(e,{method:"POST",headers:n,credentials:"include"});case 4:return i=t.sent,t.abrupt("return",i.json());case 6:case"end":return t.stop()}}),t)})),d=function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))},d.apply(this,arguments)}p.current[u]={window:i,authFinished:!1},i&&(f(!0),window.addEventListener("message",h),i.focus(),function t(r){if(!(r in p.current))return;var e=p.current[r];if(!e.window||e.window.closed)return function(t){return d.apply(this,arguments)}({botId:r}).then((function(t){s("user"in t&&t.user)})).catch((function(){f(!1),null==c||c()}));setTimeout((function(){return t(r)}),100)}(u))},{isPending:s}]};export{u as useTelegramLogin};
|
|
3
|
-
//# sourceMappingURL=use-telegram-login.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-telegram-login.js","sources":["../../../src/hooks/use-telegram-login.ts"],"sourcesContent":["import { useRef, useState } from 'react'\n\nconst POPUP_WIDTH = 550\nconst POPUP_HEIGHT = 470\nconst POPUP_ORIGIN = 'https://oauth.telegram.org'\n\nexport interface TelegramLoginData {\n /**\n * Unix timestamp indicating when the authentication occurred.\n */\n auth_date: number\n /**\n * User's first name.\n */\n first_name: string\n /**\n * Data hash for verification of the authentication data integrity.\n */\n hash: string\n /**\n * Unique identifier for the user.\n */\n id: number\n /**\n * User's last name, if available.\n */\n last_name?: string\n /**\n * URL of the user's profile photo, if available.\n */\n photo_url?: string\n /**\n * User's username, if available.\n */\n username?: string\n}\n\nexport interface UseTelegramLoginOptions {\n /**\n * The unique identifier of the Telegram bot. You can obtain it from the https://t.me/username_to_id_bot.\n */\n botId: number\n\n /**\n * Optional callback function that will be called when the login process completes successfully.\n * @param {TelegramUserData} data - The authentication data returned from Telegram.\n */\n onSuccess?: (data: TelegramLoginData) => unknown\n\n /**\n * Optional callback function that will be called if an error occurs during the login process.\n */\n onFail?: () => unknown\n}\n\nexport const useTelegramLogin = ({\n botId,\n onFail,\n onSuccess,\n}: UseTelegramLoginOptions) => {\n const [isPending, setIsPending] = useState(false)\n const popups = useRef<\n Record<number, { window: Window | null; authFinished: boolean }>\n >({})\n\n return [\n () => {\n const width = POPUP_WIDTH\n const height = POPUP_HEIGHT\n const left = Math.max(0, (screen.width - width) / 2) + screen.availWidth\n const top = Math.max(0, (screen.height - height) / 2) + screen.availHeight\n\n const popupUrl =\n POPUP_ORIGIN +\n '/auth?bot_id=' +\n encodeURIComponent(botId) +\n '&origin=' +\n encodeURIComponent(\n location.origin || location.protocol + '//' + location.hostname,\n ) +\n '&return_to=' +\n encodeURIComponent(location.href)\n\n const popup = window.open(\n popupUrl,\n 'telegram_oauth_bot' + botId,\n 'width=' +\n width +\n ',height=' +\n height +\n ',left=' +\n left +\n ',top=' +\n top +\n ',status=0,location=0,menubar=0,toolbar=0',\n )\n\n popups.current[botId] = {\n window: popup,\n authFinished: false,\n }\n\n if (popup) {\n setIsPending(true)\n window.addEventListener('message', onMessage)\n popup.focus()\n checkClose(botId)\n }\n\n function onMessage(event: MessageEvent<string>) {\n if (event.source !== popups.current[botId].window) return\n if (!(botId in popups.current)) return\n\n const data: { event: string; result: TelegramLoginData | false } =\n JSON.parse(event.data)\n\n if (data.event === 'auth_result') {\n onAuth(data.result)\n }\n }\n\n function onAuth(authData: TelegramLoginData | false) {\n if (!(botId in popups.current)) return\n if (popups.current[botId].authFinished) return\n\n if (authData) {\n onSuccess?.(authData)\n } else {\n onFail?.()\n }\n\n setIsPending(false)\n popups.current[botId].authFinished = true\n window.removeEventListener('message', onMessage)\n }\n\n function checkClose(botId: number) {\n if (!(botId in popups.current)) return\n\n const currentPopup = popups.current[botId]\n\n if (!currentPopup.window || currentPopup.window.closed) {\n return getAuthData({ botId })\n .then((res) => {\n if ('user' in res) {\n onAuth(res.user)\n } else {\n onAuth(false)\n }\n })\n .catch(() => {\n setIsPending(false)\n onFail?.()\n })\n }\n\n setTimeout(() => checkClose(botId), 100)\n }\n\n async function getAuthData(options: { botId: number }): Promise<\n ({ user: TelegramLoginData } | { error: string }) & {\n html: string\n origin: string\n }\n > {\n const url =\n POPUP_ORIGIN +\n '/auth/get' +\n '?bot_id=' +\n encodeURIComponent(options.botId)\n\n const headers = {\n 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',\n 'X-Requested-With': 'XMLHttpRequest',\n }\n\n const response = await fetch(url, {\n method: 'POST',\n headers,\n credentials: 'include',\n })\n\n return response.json()\n }\n },\n { isPending },\n ] as const\n}\n"],"names":["POPUP_ORIGIN","useTelegramLogin","_ref","botId","onFail","onSuccess","_useState2","_slicedToArray","useState","isPending","setIsPending","popups","useRef","left","Math","max","screen","width","availWidth","top","height","availHeight","popupUrl","encodeURIComponent","location","origin","protocol","hostname","href","popup","window","open","onMessage","event","source","current","data","JSON","parse","onAuth","result","authData","authFinished","removeEventListener","_getAuthData","_regeneratorRuntime","mark","_callee","options","url","headers","response","wrap","_context","prev","next","fetch","method","credentials","sent","abrupt","json","stop","apply","this","arguments","addEventListener","focus","checkClose","currentPopup","closed","_x","getAuthData","then","res","user","setTimeout"],"mappings":";++OAEA,IAEMA,EAAe,6BAmDRC,EAAmB,SAAHC,GAIE,IAH7BC,EAAKD,EAALC,MACAC,EAAMF,EAANE,OACAC,EAASH,EAATG,UAEiDC,EAAAC,EAAfC,GAAS,GAAM,GAA1CC,EAASH,EAAA,GAAEI,EAAYJ,EAAA,GACxBK,EAASC,EAEb,IAEF,MAAO,CACL,WACE,IAEMC,EAAOC,KAAKC,IAAI,GAAIC,OAAOC,MAnEnB,KAmEoC,GAAKD,OAAOE,WACxDC,EAAML,KAAKC,IAAI,GAAIC,OAAOI,OAnEjB,KAmEoC,GAAKJ,OAAOK,YAEzDC,EACJtB,EACA,gBACAuB,mBAAmBpB,GACnB,WACAoB,mBACEC,SAASC,QAAUD,SAASE,SAAW,KAAOF,SAASG,UAEzD,cACAJ,mBAAmBC,SAASI,MAExBC,EAAQC,OAAOC,KACnBT,EACA,qBAAuBnB,EACvB,6BAKEU,EACA,QACAM,EACA,4CAeJ,SAASa,EAAUC,GACjB,GAAIA,EAAMC,SAAWvB,EAAOwB,QAAQhC,GAAO2B,QACrC3B,KAASQ,EAAOwB,QAAtB,CAEA,IAAMC,EACJC,KAAKC,MAAML,EAAMG,MAEA,gBAAfA,EAAKH,OACPM,EAAOH,EAAKI,OANkB,CAQlC,CAEA,SAASD,EAAOE,GACRtC,KAASQ,EAAOwB,UAClBxB,EAAOwB,QAAQhC,GAAOuC,eAEtBD,EACFpC,SAAAA,EAAYoC,GAEZrC,SAAAA,IAGFM,GAAa,GACbC,EAAOwB,QAAQhC,GAAOuC,cAAe,EACrCZ,OAAOa,oBAAoB,UAAWX,IACxC,CAyB0B,SAAAY,UAwBzB,SAxByBC,IAAAC,MAA1B,SAAAC,EAA2BC,GAA0B,IAAAC,EAAAC,EAAAC,EAAA,OAAAN,IAAAO,MAAA,SAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,KAAA,EAelD,OATKN,EACJjD,sBAGAuB,mBAAmByB,EAAQ7C,OAEvB+C,EAAU,CACd,eAAgB,mDAChB,mBAAoB,kBACrBG,EAAAE,KAAA,EAEsBC,MAAMP,EAAK,CAChCQ,OAAQ,OACRP,QAAAA,EACAQ,YAAa,YACb,KAAA,EAJY,OAARP,EAAQE,EAAAM,KAAAN,EAAAO,OAAA,SAMPT,EAASU,QAAM,KAAA,EAAA,IAAA,MAAA,OAAAR,EAAAS,OAAA,GAAAf,EAAA,IAvBEH,gLAwBzBA,EAAAmB,MAAAC,KAAAC,UAAA,CAtFDtD,EAAOwB,QAAQhC,GAAS,CACtB2B,OAAQD,EACRa,cAAc,GAGZb,IACFnB,GAAa,GACboB,OAAOoC,iBAAiB,UAAWlC,GACnCH,EAAMsC,QA+BR,SAASC,EAAWjE,GAClB,KAAMA,KAASQ,EAAOwB,SAAU,OAEhC,IAAMkC,EAAe1D,EAAOwB,QAAQhC,GAEpC,IAAKkE,EAAavC,QAAUuC,EAAavC,OAAOwC,OAC9C,OAeH,SAEyBC,GAAA,OAAA3B,EAAAmB,MAAAC,KAAAC,UAAA,CAjBfO,CAAY,CAAErE,MAAAA,IAClBsE,MAAK,SAACC,GAEHnC,EADE,SAAUmC,GACLA,EAAIC,KAIf,IAAE,OACK,WACLjE,GAAa,GACbN,SAAAA,GACF,IAGJwE,YAAW,WAAA,OAAMR,EAAWjE,EAAM,GAAE,IACtC,CAnDEiE,CAAWjE,GA8Ef,EACA,CAAEM,UAAAA,GAEN"}
|
package/dist/esm/index.js
DELETED
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|