Spaces:
Running
Running
fix login
Browse files
src/lib/components/billing/BillingManagementModal.svelte
CHANGED
|
@@ -13,9 +13,7 @@
|
|
| 13 |
enterprise: 'bg-green-500/10 text-green-600'
|
| 14 |
};
|
| 15 |
let billingOption = $derived(authState.user?.billingOption || 'personal');
|
| 16 |
-
let selectedOrg = $derived(
|
| 17 |
-
authState.user?.orgs?.find((org) => org.preferred_username === billingOption)
|
| 18 |
-
);
|
| 19 |
let loading = $state.raw<boolean>(false);
|
| 20 |
|
| 21 |
async function saveSettings() {
|
|
@@ -26,7 +24,7 @@
|
|
| 26 |
if (billingOption === 'personal') {
|
| 27 |
localStorage.removeItem('hf-playground-billing-option');
|
| 28 |
} else {
|
| 29 |
-
localStorage.setItem('hf-playground-billing-option', selectedOrg?.
|
| 30 |
}
|
| 31 |
authState.user!.billingOption = billingOption;
|
| 32 |
open = false;
|
|
@@ -71,8 +69,12 @@
|
|
| 71 |
{authState.user?.name}
|
| 72 |
<span class="text-xs text-muted-foreground">(Personal Account)</span>
|
| 73 |
{:else}
|
| 74 |
-
<img
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
{#if selectedOrg?.plan}
|
| 77 |
<span
|
| 78 |
class="rounded px-1 py-0.5 text-[10px] font-semibold {planColors[
|
|
@@ -97,10 +99,10 @@
|
|
| 97 |
</div>
|
| 98 |
</Select.Item>
|
| 99 |
{#each authState.user?.orgs as org}
|
| 100 |
-
<Select.Item value={org.
|
| 101 |
<div class="flex items-center gap-2 text-sm">
|
| 102 |
-
<img src={org.
|
| 103 |
-
{org.name}
|
| 104 |
{#if org.plan}
|
| 105 |
<span
|
| 106 |
class="rounded px-1 py-0.5 text-[10px] font-semibold {planColors[
|
|
|
|
| 13 |
enterprise: 'bg-green-500/10 text-green-600'
|
| 14 |
};
|
| 15 |
let billingOption = $derived(authState.user?.billingOption || 'personal');
|
| 16 |
+
let selectedOrg = $derived(authState.user?.orgs?.find((org) => org.name === billingOption));
|
|
|
|
|
|
|
| 17 |
let loading = $state.raw<boolean>(false);
|
| 18 |
|
| 19 |
async function saveSettings() {
|
|
|
|
| 24 |
if (billingOption === 'personal') {
|
| 25 |
localStorage.removeItem('hf-playground-billing-option');
|
| 26 |
} else {
|
| 27 |
+
localStorage.setItem('hf-playground-billing-option', selectedOrg?.name ?? '');
|
| 28 |
}
|
| 29 |
authState.user!.billingOption = billingOption;
|
| 30 |
open = false;
|
|
|
|
| 69 |
{authState.user?.name}
|
| 70 |
<span class="text-xs text-muted-foreground">(Personal Account)</span>
|
| 71 |
{:else}
|
| 72 |
+
<img
|
| 73 |
+
src={selectedOrg?.avatarUrl}
|
| 74 |
+
alt={selectedOrg?.fullname || selectedOrg?.name}
|
| 75 |
+
class="size-5 rounded"
|
| 76 |
+
/>
|
| 77 |
+
{selectedOrg?.fullname || selectedOrg?.name}
|
| 78 |
{#if selectedOrg?.plan}
|
| 79 |
<span
|
| 80 |
class="rounded px-1 py-0.5 text-[10px] font-semibold {planColors[
|
|
|
|
| 99 |
</div>
|
| 100 |
</Select.Item>
|
| 101 |
{#each authState.user?.orgs as org}
|
| 102 |
+
<Select.Item value={org.name} class="p-2.5!">
|
| 103 |
<div class="flex items-center gap-2 text-sm">
|
| 104 |
+
<img src={org.avatarUrl} alt={org.fullname || org.name} class="size-5 rounded" />
|
| 105 |
+
{org.fullname || org.name}
|
| 106 |
{#if org.plan}
|
| 107 |
<span
|
| 108 |
class="rounded px-1 py-0.5 text-[10px] font-semibold {planColors[
|
src/lib/components/flow/actions/PanelLeftMenu.svelte
CHANGED
|
@@ -5,7 +5,6 @@
|
|
| 5 |
import { Button, buttonVariants } from '$lib/components/ui/button';
|
| 6 |
import * as Sheet from '$lib/components/ui/sheet/index.js';
|
| 7 |
import HFLogo from '$lib/assets/hf-logo.svg';
|
| 8 |
-
import { login } from '$lib/state/auth.svelte';
|
| 9 |
</script>
|
| 10 |
|
| 11 |
<Sheet.Root>
|
|
|
|
| 5 |
import { Button, buttonVariants } from '$lib/components/ui/button';
|
| 6 |
import * as Sheet from '$lib/components/ui/sheet/index.js';
|
| 7 |
import HFLogo from '$lib/assets/hf-logo.svg';
|
|
|
|
| 8 |
</script>
|
| 9 |
|
| 10 |
<Sheet.Root>
|
src/lib/helpers/types.ts
CHANGED
|
@@ -51,11 +51,11 @@ export interface TokenUsage {
|
|
| 51 |
}
|
| 52 |
|
| 53 |
export interface HFUser {
|
| 54 |
-
id: string;
|
| 55 |
name: string;
|
| 56 |
username: string;
|
|
|
|
| 57 |
avatarUrl: string;
|
| 58 |
-
orgs?: {
|
| 59 |
billingOption: string;
|
| 60 |
}
|
| 61 |
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
export interface HFUser {
|
|
|
|
| 54 |
name: string;
|
| 55 |
username: string;
|
| 56 |
+
isPro: boolean;
|
| 57 |
avatarUrl: string;
|
| 58 |
+
orgs?: { name: string; avatarUrl: string; plan?: string; fullname: string }[];
|
| 59 |
billingOption: string;
|
| 60 |
}
|
| 61 |
|
src/lib/state/auth.svelte.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const authState = $state<{ user: HFUser | null; token: string | null; loa
|
|
| 10 |
|
| 11 |
async function fetchUser(token: string): Promise<HFUser | null> {
|
| 12 |
try {
|
| 13 |
-
const res = await fetch('https://huggingface.co/
|
| 14 |
headers: { Authorization: `Bearer ${token}` }
|
| 15 |
});
|
| 16 |
if (!res.ok) return null;
|
|
@@ -21,10 +21,10 @@ async function fetchUser(token: string): Promise<HFUser | null> {
|
|
| 21 |
billingOption = 'personal';
|
| 22 |
}
|
| 23 |
return {
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
orgs: userInfo.orgs,
|
| 29 |
billingOption
|
| 30 |
};
|
|
|
|
| 10 |
|
| 11 |
async function fetchUser(token: string): Promise<HFUser | null> {
|
| 12 |
try {
|
| 13 |
+
const res = await fetch('https://huggingface.co/api/whoami-v2', {
|
| 14 |
headers: { Authorization: `Bearer ${token}` }
|
| 15 |
});
|
| 16 |
if (!res.ok) return null;
|
|
|
|
| 21 |
billingOption = 'personal';
|
| 22 |
}
|
| 23 |
return {
|
| 24 |
+
name: userInfo.fullname || userInfo.name,
|
| 25 |
+
username: userInfo.name,
|
| 26 |
+
avatarUrl: userInfo.avatarUrl,
|
| 27 |
+
isPro: userInfo.isPro,
|
| 28 |
orgs: userInfo.orgs,
|
| 29 |
billingOption
|
| 30 |
};
|