2024-01-29 04:21:19 -08:00
|
|
|
import { getSupportSecret } from "../../impress-2020-config";
|
|
|
|
|
2023-08-10 15:56:36 -07:00
|
|
|
/**
|
|
|
|
* useSupport returns the Support secret that the server requires for Support
|
|
|
|
* actions... if the user has it set. For most users, this returns nothing!
|
|
|
|
*
|
2024-01-29 04:21:19 -08:00
|
|
|
* This is specifically for communications for Impress 2020, which authorizes
|
|
|
|
* support requests using a shared support secret instead of user accounts.
|
|
|
|
* (This isn't a great model, we should abandon it in favor of true authorized
|
|
|
|
* requests as we deprecate Impress 2020!)
|
|
|
|
*
|
2023-08-10 15:56:36 -07:00
|
|
|
* 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
|
|
|
|
*
|
2024-01-29 04:21:19 -08:00
|
|
|
* To become a Support user, get the `support_staff` flag set on your user
|
|
|
|
* account. Then, `getSupportSecret` will read the support secret from the HTML
|
|
|
|
* document. (If the flag is off, the HTML document does not contain the
|
|
|
|
* secret.)
|
2023-08-10 15:56:36 -07:00
|
|
|
*
|
|
|
|
* 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() {
|
2024-09-09 16:10:45 -07:00
|
|
|
const supportSecret = getSupportSecret();
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
const isSupportUser = supportSecret != null;
|
2023-08-10 15:56:36 -07:00
|
|
|
|
2024-09-09 16:10:45 -07:00
|
|
|
return { isSupportUser, supportSecret };
|
2023-08-10 15:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default useSupport;
|