Skip to content

Dropbox authentication#1367

Merged
Azgaar merged 1 commit intomasterfrom
dropdox-auth
Mar 26, 2026
Merged

Dropbox authentication#1367
Azgaar merged 1 commit intomasterfrom
dropdox-auth

Conversation

@Azgaar
Copy link
Copy Markdown
Owner

@Azgaar Azgaar commented Mar 26, 2026

…l for improved token management

Description

@Azgaar Azgaar self-assigned this Mar 26, 2026
Copilot AI review requested due to automatic review settings March 26, 2026 22:14
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit f3fe260
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/69c5afcdbaee4100082e22d0
😎 Deploy Preview https://deploy-preview-1367--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Dropbox authentication flow by replacing direct window.opener callbacks / DOM events with a BroadcastChannel-based handshake between the auth popup and the main app, aiming to improve token/error propagation and reduce tight coupling between windows.

Changes:

  • Switch Dropbox auth completion signaling from a custom window event to BroadcastChannel messaging in Cloud.providers.dropbox.auth().
  • Update public/dropbox.html to send token/error back via BroadcastChannel and close itself.
  • Minor package-lock.json metadata changes (adds "peer": true in a few entries).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.

File Description
public/modules/io/cloud.js Receives auth results via BroadcastChannel, sets token, and resolves/rejects the auth Promise.
public/dropbox.html Sends token/error messages over BroadcastChannel instead of calling window.opener APIs.
package-lock.json Adds "peer": true flags to several lockfile package entries.

Comment on lines +49 to 53
channel.close();
window.close();
})
.catch(error => {
console.error(error);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If posting the token fails or getAccessTokenFromCode rejects, the opener tab will wait until its 120s timeout because this window never reports the failure via the channel. Consider reusing returnError(...) in the .catch(...) (and similarly in startAuth().catch(...)) so the opener can reject immediately and the auth window can close.

Copilot uses AI. Check for mistakes.
Comment on lines +98 to 101
const channel = new BroadcastChannel("dropbox-auth");
channel.onmessage = async ({data}) => {
channel.close();
clearTimeout(watchDog);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth() opens a BroadcastChannel but the timeout path only closes authWindow and rejects; the channel remains open and can still deliver a late message after the Promise is settled. Consider tracking a settled flag and closing the channel / removing the handler in the watchdog (and ignoring messages if already settled) to avoid leaks and racey state updates.

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +103
channel.onmessage = async ({data}) => {
channel.close();
clearTimeout(watchDog);
resolve();
});
if (data.type === "token") {
await this.setDropBoxToken(data.token);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channel.onmessage is async and awaits setDropBoxToken(). If setDropBoxToken / connect throws, the exception becomes an unhandled rejection and the outer auth() Promise will never resolve/reject. Wrap the body in try/catch and call reject(err) (and show an error) on failure.

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +108
if (data.type === "token") {
await this.setDropBoxToken(data.token);
resolve();
} else {
this.returnError(data.description);
reject(new Error(data.description));
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message handler assumes data.description is always a string. If error_description is missing (or a malformed message is received), returnError will throw on replaceAll and the rejection will be confusing. Guard the message schema here (e.g., default the description, and validate token exists before calling setDropBoxToken).

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +103
const channel = new BroadcastChannel("dropbox-auth");
channel.onmessage = async ({data}) => {
channel.close();
clearTimeout(watchDog);
resolve();
});
if (data.type === "token") {
await this.setDropBoxToken(data.token);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fixed channel name ("dropbox-auth") broadcasts the access token to any same-origin context currently listening on that channel (e.g., another open FMG tab doing Dropbox auth). This can cause cross-tab interference (wrong tab resolves, orphaned auth windows) and unnecessarily widens token exposure. Consider generating a per-auth nonce/channel name and passing it to dropbox.html (e.g., via query string) so only the initiating window receives the token/error.

Copilot uses AI. Check for mistakes.
Comment on lines 19 to 21
if (code) getToken();
else if (error) window.opener.Cloud.providers.dropbox.returnError(params.get("error_description"));
else if (error) returnError(params.get("error_description"));
else startAuth();
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params.get("error_description") can be null, which will then be broadcast and eventually crash returnError in the opener (it calls replaceAll on the value). Provide a fallback string before calling returnError (and/or coerce description to a string inside returnError).

Copilot uses AI. Check for mistakes.
@Azgaar Azgaar merged commit b7af737 into master Mar 26, 2026
12 checks passed
@Azgaar Azgaar deleted the dropdox-auth branch March 26, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants