Skip to content

Commit 1cca36a

Browse files
committed
feat: add auth mode and corrected session call
1 parent aae8394 commit 1cca36a

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
VITE_API_URL=http://localhost:5312
1+
VITE_API_URL=http://localhost:3000
2+
VITE_AUTH_MODE=server

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Profile from "./pages/Profile";
2222

2323
export default function App() {
2424
return (
25-
<AuthProvider apiHost={API_URL} mode="web">
25+
<AuthProvider apiHost={API_URL} mode="server">
2626
<Routes>
2727
<Route path="/unauthenticated" element={<Unauthenticated />} />
2828

src/hooks/useRevokeSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function useRevokeSession() {
1313

1414
return useMutation({
1515
mutationFn: (id: string) =>
16-
apiFetch(`/sessions/${id}`, {
16+
apiFetch(`/admin/sessions/${id}`, {
1717
method: "DELETE",
1818
}),
1919
onSuccess: () => {

src/lib/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See LICENSE file in the project root for full license information
55
*/
66

7-
import { getApiUrl } from "./runtimeConfig";
7+
import { getApiUrl, getAuthMode } from "./runtimeConfig";
88

99
export const API_URL = getApiUrl();
1010

@@ -16,7 +16,9 @@ export async function apiFetch<T>(
1616

1717
headers.set("Content-Type", "application/json");
1818

19-
const res = await fetch(`${API_URL}${path}`, {
19+
const adapater = getAuthMode() === "server" ? "auth" : "";
20+
21+
const res = await fetch(`${API_URL}${adapater}${path}`, {
2022
credentials: "include",
2123
...options,
2224
headers,

src/lib/runtimeConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare global {
88
interface Window {
99
__SEAMLESS_CONFIG__?: {
1010
API_URL: string;
11+
AUTH_MODE: string;
1112
};
1213
}
1314
}
@@ -19,3 +20,11 @@ export function getApiUrl(): string {
1920

2021
return import.meta.env.VITE_API_URL;
2122
}
23+
24+
export function getAuthMode(): string {
25+
if (window.__SEAMLESS_CONFIG__?.AUTH_MODE) {
26+
return window.__SEAMLESS_CONFIG__.AUTH_MODE;
27+
}
28+
29+
return import.meta.env.VITE_AUTH_MODE;
30+
}

0 commit comments

Comments
 (0)