jamesspearsv / libstats-node

Reference interaction collection tool built on NodeJS, Express, and React
1 stars 0 forks source link

Improve authorization response evaluation in admin components #49

Closed jamesspearsv closed 1 week ago

jamesspearsv commented 2 weeks ago

Add a utility function to evaluate API response status and set auth if needed.

Example

const res = await fetch(url, options);
const json = await res.json();

// evaluate response status function
if (res.status === 401) {
    toast.error("Session expired")
    return setAuth(null);
} else if (!res.ok) throw new Error(message);