onairos 0.1.216 → 0.1.217

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.
@@ -5,26 +5,42 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = GoogleButton;
7
7
  var _google = require("@react-oauth/google");
8
+ var _jwtDecode = require("jwt-decode");
8
9
  var _jsxRuntime = require("react/jsx-runtime");
9
10
  function GoogleButton(_ref) {
10
11
  let {
11
- onSuccess
12
+ onLoginSuccess
12
13
  } = _ref;
13
- const login = (0, _google.useGoogleLogin)({
14
- onSuccess: tokenResponse => {
15
- onSuccess(tokenResponse);
14
+ const handleGoogleSuccess = async credentialResponse => {
15
+ try {
16
+ const decoded = (0, _jwtDecode.jwtDecode)(credentialResponse.credential);
17
+ const response = await fetch('https://api2.onairos.uk/auth/google', {
18
+ method: 'POST',
19
+ headers: {
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ body: JSON.stringify({
23
+ token: credentialResponse.credential,
24
+ email: decoded.email
25
+ })
26
+ });
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
+ } catch (error) {
34
+ console.error('Google login failed:', error);
16
35
  }
17
- });
36
+ };
18
37
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
19
38
  className: "flex flex-col items-center",
20
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
21
- onClick: () => login(),
22
- className: "w-12 h-12 rounded-full shadow-md hover:shadow-lg transition-shadow duration-200 flex items-center justify-center bg-white",
23
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
24
- src: "https://onairos.sirv.com/Images/google-icon.png",
25
- alt: "Google",
26
- className: "w-6 h-6"
27
- })
39
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_google.GoogleLogin, {
40
+ onSuccess: handleGoogleSuccess,
41
+ onError: () => console.error('Google Login Failed'),
42
+ shape: "circle",
43
+ theme: "outline"
28
44
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
29
45
  className: "text-xs mt-2 text-gray-600",
30
46
  children: "Google"
@@ -5,27 +5,60 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = OnairosAppButton;
7
7
  var _react = require("react");
8
- var _deepLinking = require("../utils/deepLinking");
9
8
  var _biometrics = require("../utils/biometrics");
10
9
  var _jsxRuntime = require("react/jsx-runtime");
11
10
  function OnairosAppButton(_ref) {
12
11
  let {
13
- hasSavedCredentials,
14
- onSuccess
12
+ onLoginSuccess
15
13
  } = _ref;
16
14
  const [loading, setLoading] = (0, _react.useState)(false);
15
+ const verifySavedCredentials = async () => {
16
+ const savedCredentials = localStorage.getItem('onairosCredentials');
17
+ if (!savedCredentials) return null;
18
+ try {
19
+ const credentials = JSON.parse(savedCredentials);
20
+ const response = await fetch('https://api2.onairos.uk/verify', {
21
+ method: 'POST',
22
+ headers: {
23
+ 'Content-Type': 'application/json'
24
+ },
25
+ body: JSON.stringify({
26
+ username: credentials.username,
27
+ token: credentials.token
28
+ })
29
+ });
30
+ if (!response.ok) {
31
+ localStorage.removeItem('onairosCredentials');
32
+ return null;
33
+ }
34
+ return credentials;
35
+ } catch (error) {
36
+ console.error('Verification failed:', error);
37
+ return null;
38
+ }
39
+ };
17
40
  const handleAppLogin = async () => {
18
41
  setLoading(true);
19
42
  try {
20
- if (hasSavedCredentials) {
43
+ const credentials = await verifySavedCredentials();
44
+ if (credentials) {
21
45
  const isAuthenticated = await (0, _biometrics.authenticateWithBiometrics)();
22
46
  if (isAuthenticated) {
23
- const credentials = JSON.parse(localStorage.getItem('onairosCredentials'));
24
- onSuccess(credentials);
47
+ await onLoginSuccess(credentials.username);
48
+ return;
25
49
  }
26
- } else {
27
- await (0, _deepLinking.launchOnairosApp)();
28
50
  }
51
+
52
+ // If no credentials or biometrics failed, launch app
53
+ const nonce = Date.now();
54
+ const returnLink = encodeURIComponent(window.location.origin + '/auth/callback');
55
+ const onairosUrl = `onairos://authenticate?nonce=${nonce}&callback=${returnLink}&appName=google`;
56
+ window.location.href = onairosUrl;
57
+
58
+ // Fallback to app store after timeout
59
+ setTimeout(() => {
60
+ window.location.href = 'https://apps.apple.com/app/onairos/id123456789';
61
+ }, 2500);
29
62
  } catch (error) {
30
63
  console.error('App login failed:', error);
31
64
  } finally {