impress/app/javascript/wardrobe-2020/WardrobePage/support/useSupport.js
Matchu e300b2d342 Run Prettier on all wardrobe-2020 JS
Looks like the version of Prettier I just installed is v3, whereas our
last run in the impress-2020 repo was with v2. I don't think we had any
special config in that project, I think these are just changes to
Prettier's defaults, and I'm comfortable accepting them! (Mostly seems
like a lot of trailing commas.)
2023-10-24 16:45:49 -07:00

32 lines
1,007 B
JavaScript

import * as React from "react";
/**
* useSupport returns the Support secret that the server requires for Support
* actions... if the user has it set. For most users, this returns nothing!
*
* Specifically, we return an object of:
* - isSupportUser: true iff the `supportSecret` is set
* - supportSecret: the secret saved to this device, or null if not set
*
* To become a Support user, you visit /?supportSecret=..., which saves the
* secret to your device.
*
* Note that this hook doesn't check that the secret is *correct*, so it's
* possible that it will return an invalid secret. That's okay, because
* the server checks the provided secret for each Support request.
*/
function useSupport() {
const supportSecret = React.useMemo(
() =>
typeof localStorage !== "undefined"
? localStorage.getItem("supportSecret")
: null,
[],
);
const isSupportUser = supportSecret != null;
return { isSupportUser, supportSecret };
}
export default useSupport;