onairos 0.1.334 → 0.1.336

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.
@@ -38,8 +38,7 @@ function AuthButtons(_ref) {
38
38
  };
39
39
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
40
40
  className: "flex flex-row justify-center items-center space-x-4",
41
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_OthentButton.default, {
42
- onSuccess: handleOthentSuccess,
41
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(GoogleButton, {
43
42
  onLoginSuccess: othentLogin
44
43
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_OnairosAppButton.default, {
45
44
  hasSavedCredentials: hasSavedCredentials,
@@ -4,46 +4,57 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = GoogleButton;
7
- var _google = require("@react-oauth/google");
8
- var _jwtDecode = require("jwt-decode");
9
7
  var _jsxRuntime = require("react/jsx-runtime");
10
8
  function GoogleButton(_ref) {
11
9
  let {
12
10
  onLoginSuccess
13
11
  } = _ref;
14
- const handleGoogleSuccess = async credentialResponse => {
12
+ const handleTelegramAuth = async () => {
15
13
  try {
16
- const decoded = (0, _jwtDecode.jwtDecode)(credentialResponse.credential);
17
- const response = await fetch('https://api2.onairos.uk/login/google-signin', {
18
- method: 'POST',
19
- headers: {
20
- 'Content-Type': 'application/json'
21
- },
22
- body: JSON.stringify({
23
- token: credentialResponse.credential,
24
- email: decoded.email
25
- })
14
+ // Get Telegram Mini App data
15
+ const telegramAppUrl = window.Telegram.WebApp.initData;
16
+ const botUsername = 'OnairosMiniApp';
17
+
18
+ // Construct URL to your Othent connect page
19
+ const connectUrl = new URL('https://onairos.uk/othent-connect');
20
+ connectUrl.searchParams.append('tgAppUrl', telegramAppUrl);
21
+ connectUrl.searchParams.append('botUsername', botUsername);
22
+ connectUrl.searchParams.append('startApp', window.Telegram.WebApp.initDataUnsafe?.start_param || '');
23
+
24
+ // Open in browser
25
+ window.open(connectUrl.toString(), '_blank');
26
+
27
+ // Listen for Telegram WebApp events
28
+ window.Telegram.WebApp.onEvent('popupClosed', async params => {
29
+ const startParam = window.Telegram.WebApp.initDataUnsafe?.start_param;
30
+ if (startParam) {
31
+ try {
32
+ const authData = JSON.parse(decodeURIComponent(startParam));
33
+ if (authData.sub && authData.token) {
34
+ onLoginSuccess(authData);
35
+ }
36
+ } catch (error) {
37
+ console.error('Error processing auth data:', error);
38
+ }
39
+ }
26
40
  });
27
- if (!response.ok) {
28
- throw new Error('Google authentication failed');
29
- }
30
- const data = await response.json();
31
- localStorage.setItem('onairosToken', data.token);
32
- await onLoginSuccess(decoded.email);
33
41
  } catch (error) {
34
- console.error('Google login failed:', error);
42
+ console.error('Telegram auth flow failed:', error);
35
43
  }
36
44
  };
37
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
45
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
38
46
  className: "flex flex-col items-center",
39
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_google.GoogleLogin, {
40
- onSuccess: handleGoogleSuccess,
41
- onError: () => console.error('Google Login Failed'),
42
- shape: "circle",
43
- theme: "outline"
44
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
45
- className: "text-xs mt-2 text-gray-600",
46
- children: "Google"
47
- })]
47
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
48
+ onClick: handleTelegramAuth,
49
+ className: "flex items-center justify-center px-4 py-2 border border-gray-300 rounded-full shadow-sm bg-white hover:bg-gray-50",
50
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
51
+ src: "https://imagepng.org/google-icone-icon/google-icon/" // Replace with actual Othent icon
52
+ ,
53
+ alt: "Google",
54
+ className: "w-5 h-5 mr-2"
55
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
56
+ children: "Continue with Google"
57
+ })]
58
+ })
48
59
  });
49
60
  }