Skip to content

newGetUser() fires before window.load in auth.js #18

Description

@rioredwards

Location

auth/auth.js:9

Problem

newGetUser() is called at module parse time, before the window.load event fires:

// runs immediately at parse time
newGetUser();

// runs after DOM is fully ready
window.addEventListener('load', () => {
    displayAuth();
});

The network call itself is harmless before load, but the pattern is inconsistent with the rest of the file and could cause ordering issues if newGetUser is ever extended to touch the DOM.

Suggested fix

Either move the call inside the load handler, or add a comment explaining the intentional early-call:

window.addEventListener('load', async () => {
    // redirect immediately if already signed in
    const user = await getUser();
    if (user) location.replace('/');
    displayAuth();
});

This consolidates startup logic in one place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions