@lovable.dev/cloud-auth-js 1.0.1 → 1.1.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/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ var EXPECTED_MESSAGE_TYPE = "authorization_response";
29
29
  var DEFAULT_OAUTH_BROKER_URL = "/~oauth/initiate";
30
30
  var DEFAULT_SUPPORTED_OAUTH_ORIGINS = ["https://oauth.lovable.app", "https://lovable.dev"];
31
31
  var DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI = "lovable://oauth-callback";
32
+ var DEFAULT_DESKTOP_LOCALHOST_REDIRECT_URI = "http://127.0.0.1/iframe-oauth/callback";
32
33
  var POPUP_CHECK_INTERVAL_MS = 500;
33
34
  var IFRAME_FALLBACK_TIMEOUT_MS = 12e4;
34
35
  function startWebMessageListener(supportedOrigins) {
@@ -106,8 +107,14 @@ function createAuth(config = {}) {
106
107
  const ua = navigator.userAgent;
107
108
  const isMobile = /iPhone|iPad|iPod|Android/i.test(ua);
108
109
  const isMobileApp = /LovableApp\//.test(ua);
110
+ const isDesktopApp = /lovable-?desktop\//i.test(ua);
109
111
  const state = generateState();
110
- const redirectUri = isMobileApp && isInIframe ? DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI : opts.redirect_uri ?? window.location.origin;
112
+ let redirectUri = opts.redirect_uri ?? window.location.origin;
113
+ if (isMobileApp && isInIframe) {
114
+ redirectUri = DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI;
115
+ } else if (isDesktopApp && isInIframe) {
116
+ redirectUri = DEFAULT_DESKTOP_LOCALHOST_REDIRECT_URI;
117
+ }
111
118
  const params = new URLSearchParams({
112
119
  ...opts.extraParams,
113
120
  provider,
@@ -118,11 +125,12 @@ function createAuth(config = {}) {
118
125
  window.location.href = `${oauthBrokerUrl}?${params.toString()}`;
119
126
  return { error: null, redirected: true };
120
127
  }
121
- if (!isMobileApp) {
128
+ if (!isMobileApp && !isDesktopApp) {
122
129
  params.set("response_mode", "web_message");
123
130
  }
124
131
  const url = `${oauthBrokerUrl}?${params.toString()}`;
125
- const { messagePromise, cleanup } = startWebMessageListener(supportedOAuthOrigins);
132
+ const effectiveOrigins = isDesktopApp ? [...supportedOAuthOrigins, window.location.origin] : supportedOAuthOrigins;
133
+ const { messagePromise, cleanup } = startWebMessageListener(effectiveOrigins);
126
134
  let popup;
127
135
  if (isMobile) {
128
136
  popup = window.open(url, "_blank");
@@ -130,7 +138,7 @@ function createAuth(config = {}) {
130
138
  const { width, height, left, top } = getPopupDimensions(isInIframe);
131
139
  popup = window.open(url, "oauth", `width=${width},height=${height},left=${left},top=${top}`);
132
140
  }
133
- if (!popup && isMobileApp) {
141
+ if (!popup && (isMobileApp || isDesktopApp)) {
134
142
  let webViewTimeoutId;
135
143
  const webViewTimeoutPromise = new Promise((_, reject) => {
136
144
  webViewTimeoutId = setTimeout(() => {
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ var EXPECTED_MESSAGE_TYPE = "authorization_response";
3
3
  var DEFAULT_OAUTH_BROKER_URL = "/~oauth/initiate";
4
4
  var DEFAULT_SUPPORTED_OAUTH_ORIGINS = ["https://oauth.lovable.app", "https://lovable.dev"];
5
5
  var DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI = "lovable://oauth-callback";
6
+ var DEFAULT_DESKTOP_LOCALHOST_REDIRECT_URI = "http://127.0.0.1/iframe-oauth/callback";
6
7
  var POPUP_CHECK_INTERVAL_MS = 500;
7
8
  var IFRAME_FALLBACK_TIMEOUT_MS = 12e4;
8
9
  function startWebMessageListener(supportedOrigins) {
@@ -80,8 +81,14 @@ function createAuth(config = {}) {
80
81
  const ua = navigator.userAgent;
81
82
  const isMobile = /iPhone|iPad|iPod|Android/i.test(ua);
82
83
  const isMobileApp = /LovableApp\//.test(ua);
84
+ const isDesktopApp = /lovable-?desktop\//i.test(ua);
83
85
  const state = generateState();
84
- const redirectUri = isMobileApp && isInIframe ? DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI : opts.redirect_uri ?? window.location.origin;
86
+ let redirectUri = opts.redirect_uri ?? window.location.origin;
87
+ if (isMobileApp && isInIframe) {
88
+ redirectUri = DEFAULT_MOBILE_DEEP_LINK_REDIRECT_URI;
89
+ } else if (isDesktopApp && isInIframe) {
90
+ redirectUri = DEFAULT_DESKTOP_LOCALHOST_REDIRECT_URI;
91
+ }
85
92
  const params = new URLSearchParams({
86
93
  ...opts.extraParams,
87
94
  provider,
@@ -92,11 +99,12 @@ function createAuth(config = {}) {
92
99
  window.location.href = `${oauthBrokerUrl}?${params.toString()}`;
93
100
  return { error: null, redirected: true };
94
101
  }
95
- if (!isMobileApp) {
102
+ if (!isMobileApp && !isDesktopApp) {
96
103
  params.set("response_mode", "web_message");
97
104
  }
98
105
  const url = `${oauthBrokerUrl}?${params.toString()}`;
99
- const { messagePromise, cleanup } = startWebMessageListener(supportedOAuthOrigins);
106
+ const effectiveOrigins = isDesktopApp ? [...supportedOAuthOrigins, window.location.origin] : supportedOAuthOrigins;
107
+ const { messagePromise, cleanup } = startWebMessageListener(effectiveOrigins);
100
108
  let popup;
101
109
  if (isMobile) {
102
110
  popup = window.open(url, "_blank");
@@ -104,7 +112,7 @@ function createAuth(config = {}) {
104
112
  const { width, height, left, top } = getPopupDimensions(isInIframe);
105
113
  popup = window.open(url, "oauth", `width=${width},height=${height},left=${left},top=${top}`);
106
114
  }
107
- if (!popup && isMobileApp) {
115
+ if (!popup && (isMobileApp || isDesktopApp)) {
108
116
  let webViewTimeoutId;
109
117
  const webViewTimeoutPromise = new Promise((_, reject) => {
110
118
  webViewTimeoutId = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/cloud-auth-js",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Lovable Cloud Auth JS",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",