Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/web/src/lib/components/HeaderAuthSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

const userService = inject(USER_SERVICE);
const user = $derived(userService.user);
const userLoaded = $derived(userService.loaded);
const routes = inject(WEB_ROUTES_SERVICE);
</script>

{#if $user && !hideIfUserAuthenticated}
{#if !$user && !$userLoaded}
<div class="auth-placeholder"></div>
{:else if $user && !hideIfUserAuthenticated}
<UserAuthAvatar user={$user} />
{:else if !$user}
<div class="login-signup-wrap">
Expand All @@ -27,6 +30,10 @@
{/if}

<style lang="postcss">
.auth-placeholder {
height: var(--size-button);
}

.login-signup-wrap {
display: flex;
align-items: center;
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/lib/user/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type LoadablePatchStacks = Loadable<Branch[]> & { ownerSlug: string };
export const USER_SERVICE = new InjectionToken<UserService>("UserService");

export class UserService {
readonly loaded: Writable<boolean> = writable(false);

user: Writable<User | undefined> = writable<User | undefined>(undefined, (set) => {
this.fetchUser()
.then((data) => {
Expand All @@ -38,6 +40,9 @@ export class UserService {
})
.catch((err) => {
this.error.set(err);
})
.finally(() => {
this.loaded.set(true);
});
});

Expand All @@ -61,6 +66,9 @@ export class UserService {
})
.catch((err) => {
this.error.set(err);
})
.finally(() => {
this.loaded.set(true);
});
} else if (!available) {
// If authentication is no longer available, clear the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
const routes = inject(WEB_ROUTES_SERVICE);
const userService = inject(USER_SERVICE);
const user = userService.user;
const userLoaded = userService.loaded;

// If there is no user (user not logged in), redirect to home
$effect(() => {
if ($user === undefined) {
if ($user === undefined && $userLoaded) {
goto(routes.homePath());
}
});
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/routes/(app)/[ownerSlug]/rules/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
const routes = inject(WEB_ROUTES_SERVICE);
const userService = inject(USER_SERVICE);
const user = userService.user;
const userLoaded = userService.loaded;

// If there is no user (user not logged in), redirect to home
$effect(() => {
if ($user === undefined) {
if ($user === undefined && $userLoaded) {
goto(routes.homePath());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const organizationService = inject(ORGANIZATION_SERVICE);

const user = $derived(userService.user);
const userLoaded = $derived(userService.loaded);

// Get the org slug and invite code from the route parameters
const inviteCode = $derived($page.params.code!);
Expand Down Expand Up @@ -100,7 +101,11 @@
<div class="invite-card">
<h1>Organization Invitation</h1>

{#if !isLoggedIn}
{#if !isLoggedIn && !$userLoaded}
<div class="loading-container">
<p>Checking your invitation...</p>
</div>
{:else if !isLoggedIn}
<p>You've been invited to join <strong>{slug}</strong>.</p>
<p>Please log in to continue.</p>
<Button onclick={goToLogin} style="pop">Log In</Button>
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/routes/(app)/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
);

const user = $derived(userService.user);
const userLoaded = $derived(userService.loaded);

const detectedOS = $derived.by(() => {
const os = getOS();
Expand Down Expand Up @@ -83,7 +84,9 @@
<title>GitButler | User</title>
</svelte:head>

{#if !$user?.id}
{#if !$user?.id && !$userLoaded}
<div class="loading-user"></div>
{:else if !$user?.id}
<div class="not-logged-in">
<h3 class="text-18 text-bold">It looks like you're not logged in</h3>
<p class="text-14 text-body clr-text-2">
Expand Down Expand Up @@ -274,6 +277,11 @@
</Modal>

<style lang="postcss">
.loading-user {
grid-column: full-start / full-end;
min-height: 100%;
}

.not-logged-in {
display: flex;
row-gap: 10px;
Expand Down
Loading