forked from OpenNeo/impress
Emi Matchu
0e314482f7
I haven't been running Prettier consistently on things in this project. Now, it's quick-runnable, and I've got it on everything! Also, I just think tabs are the right default for this kind of thing, and I'm glad to get to switch over to it! (In `package.json`.)
35 lines
688 B
JavaScript
35 lines
688 B
JavaScript
// Read the current user ID once from the <meta> tags, and use that forever!
|
|
const currentUserId = readCurrentUserId();
|
|
|
|
function useCurrentUser() {
|
|
if (currentUserId == null) {
|
|
return {
|
|
isLoggedIn: false,
|
|
id: null,
|
|
};
|
|
}
|
|
|
|
return {
|
|
isLoggedIn: true,
|
|
id: currentUserId,
|
|
};
|
|
}
|
|
|
|
function readCurrentUserId() {
|
|
try {
|
|
const element = document.querySelector("meta[name=dti-current-user-id]");
|
|
const value = element.getAttribute("content");
|
|
if (value === "null") {
|
|
return null;
|
|
}
|
|
return value;
|
|
} catch (error) {
|
|
console.error(
|
|
`[readCurrentUserId] Couldn't read user ID, using null instead`,
|
|
error,
|
|
);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export default useCurrentUser;
|