Skip to content
Merged
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
2 changes: 1 addition & 1 deletion dist/core/handler.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions dist/core/handler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/core/handler.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/png" href="/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Better Auth Studio</title>
<script type="module" crossorigin src="/assets/main-CHRrIhpF.js"></script>
<script type="module" crossorigin src="/assets/main-BdtDgIJP.js"></script>
<link rel="stylesheet" crossorigin href="/assets/main-BboBzuv8.css">
</head>
<body>
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Layout from "./components/Layout";
import { CountsProvider } from "./contexts/CountsContext";
import { DashboardWidgetsProvider } from "./contexts/DashboardWidgetsContext";
import { ThemeProvider, useTheme } from "./contexts/ThemeContext";
import { fetchStudioAuthJson } from "./utils/studio-auth";
import AccessDenied from "./pages/AccessDenied";
import Dashboard from "./pages/Dashboard";
import DatabaseVisualizer from "./pages/DatabaseVisualizer";
Expand Down Expand Up @@ -39,9 +40,7 @@ function AuthGuard({ children }: { children: React.ReactNode }) {
useEffect(() => {
const checkAuth = async () => {
try {
const studioAuthPath = basePath ? `${basePath}/auth` : "/api/auth";
const response = await fetch(`${studioAuthPath}/session`, { credentials: "include" });
const data = await response.json();
const { data } = await fetchStudioAuthJson("/session");
setAuth({ loading: false, authenticated: data.authenticated, user: data.user });
} catch {
setAuth({ loading: false, authenticated: false, user: null });
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useCounts } from "../contexts/CountsContext";
import { useTheme } from "../contexts/ThemeContext";
import { useWebSocket } from "../hooks/useWebSocket";
import { buildApiUrl } from "../utils/api";
import { fetchStudioAuthJson } from "../utils/studio-auth";
import CommandPalette from "./CommandPalette";
import { LiveEventMarquee } from "./LiveEventMarquee";

Expand Down Expand Up @@ -190,9 +191,7 @@ export default function Layout({ children }: LayoutProps) {

const fetchUserProfile = async () => {
try {
const basePath = getStudioConfig().basePath || "";
const response = await fetch(`${basePath}/auth/session`, { credentials: "include" });
const data = await response.json();
const { data } = await fetchStudioAuthJson("/session");
if (data.authenticated && data.user) {
setUserProfile(data.user);
}
Expand All @@ -219,8 +218,7 @@ export default function Layout({ children }: LayoutProps) {

const handleLogout = async () => {
try {
const basePath = getStudioConfig().basePath || "";
await fetch(`${basePath}/auth/logout`, { method: "GET", credentials: "include" });
await fetchStudioAuthJson("/logout", { method: "GET" });
navigate("/login");
} catch {
navigate("/login");
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/pages/AccessDenied.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useNavigate } from "react-router-dom";
import { fetchStudioAuthJson } from "../utils/studio-auth";

export default function AccessDeniedPage() {
const navigate = useNavigate();

const handleLogout = async () => {
try {
const basePath = (window as any).__STUDIO_CONFIG__?.basePath || "";
const studioAuthPath = basePath ? `${basePath}/auth` : "/api/auth";
await fetch(`${studioAuthPath}/logout`, { credentials: "include" });
await fetchStudioAuthJson("/logout");
navigate("/login");
} catch {
navigate("/login");
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/pages/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AlertCircle, Loader } from "lucide-react";
import { useState } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { fetchStudioAuthJson } from "../utils/studio-auth";

export default function LoginPage() {
const navigate = useNavigate();
Expand All @@ -18,18 +19,12 @@ export default function LoginPage() {
setError("");

try {
const basePath = (window as any).__STUDIO_CONFIG__?.basePath || "";
const studioAuthPath = basePath ? `${basePath}/auth` : "/api/auth";

const signInResponse = await fetch(`${studioAuthPath}/sign-in`, {
const { response: signInResponse, data: result } = await fetchStudioAuthJson("/sign-in", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email, password }),
credentials: "include",
});

const result = await signInResponse.json();

if (!signInResponse.ok) {
if (signInResponse.status === 403) {
navigate("/access-denied");
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/pages/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
} from "../components/ui/select";
import { useCounts } from "../contexts/CountsContext";
import { getImageSrc } from "../lib/utils";
import { fetchStudioAuthJson } from "../utils/studio-auth";

interface User {
id: string;
Expand Down Expand Up @@ -78,10 +79,6 @@ const formatTimeAgo = (value?: string | null): string => {
return formatDistanceToNow(d, { addSuffix: true });
};

const studioConfig = (window as any).__STUDIO_CONFIG__ || {};
const basePath = studioConfig.basePath !== undefined ? studioConfig.basePath : "";
const studioAuthPath = basePath ? `${basePath}/auth` : "/api/auth";

export default function Users() {
const navigate = useNavigate();
const location = useLocation();
Expand Down Expand Up @@ -194,8 +191,7 @@ export default function Users() {
useEffect(() => {
const fetchCurrentUser = async () => {
try {
const response = await fetch(`${studioAuthPath}/session`, { credentials: "include" });
const data = await response.json();
const { data } = await fetchStudioAuthJson("/session");
if (data?.authenticated && data.user) {
setCurrentUser(data.user);
} else {
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/utils/studio-auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export function getStudioAuthPath(): string {
const basePath = (window as any).__STUDIO_CONFIG__?.basePath || "";
return basePath ? `${basePath}/auth` : "/api/auth";
}

export async function fetchStudioAuthJson(
path: string,
init: RequestInit = {},
): Promise<{ response: Response; data: any }> {
const headers = new Headers(init.headers || {});
if (!headers.has("Accept")) {
headers.set("Accept", "application/json");
}

const response = await fetch(
`${getStudioAuthPath()}${path.startsWith("/") ? path : `/${path}`}`,
{
...init,
headers,
credentials: "include",
},
);

const contentType = response.headers.get("content-type") || "";
if (!contentType.includes("application/json")) {
const fallbackBody = await response.text().catch(() => "");
const fallbackKind = fallbackBody.trim().startsWith("<") ? "HTML" : "non-JSON";
throw new Error(
response.ok
? `Server returned ${fallbackKind} instead of JSON.`
: `Request failed with ${response.status}. Server returned ${fallbackKind} instead of JSON.`,
);
}

return {
response,
data: await response.json(),
};
}
Loading
Loading