wrap auth util functions in try blocks
This commit is contained in:
@@ -2,6 +2,7 @@ import type { User } from "@chessu/types";
|
|||||||
import { API_URL } from "@/config";
|
import { API_URL } from "@/config";
|
||||||
|
|
||||||
export const fetchSession = async () => {
|
export const fetchSession = async () => {
|
||||||
|
try {
|
||||||
const res = await fetch(`${API_URL}/v1/auth`, {
|
const res = await fetch(`${API_URL}/v1/auth`, {
|
||||||
credentials: "include"
|
credentials: "include"
|
||||||
});
|
});
|
||||||
@@ -10,9 +11,13 @@ export const fetchSession = async () => {
|
|||||||
const user: User = await res.json();
|
const user: User = await res.json();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setGuestSession = async (name: string) => {
|
export const setGuestSession = async (name: string) => {
|
||||||
|
try {
|
||||||
const res = await fetch(`${API_URL}/v1/auth/guest`, {
|
const res = await fetch(`${API_URL}/v1/auth/guest`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -25,4 +30,7 @@ export const setGuestSession = async (name: string) => {
|
|||||||
const user: User = await res.json();
|
const user: User = await res.json();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user