cauthy-auth 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.mjs CHANGED
@@ -105,13 +105,17 @@ var UNAVAILABLE = { code: "unavailable", message: "Sign-in is unavailable right
105
105
  function createAuthClient(options = {}) {
106
106
  const base = (options.basePath ?? "/api/auth").replace(/\/+$/, "");
107
107
  const doFetch = (...args) => (options.fetch ?? fetch)(...args);
108
+ const locale = () => {
109
+ const said = typeof options.locale === "function" ? options.locale() : options.locale;
110
+ return (said ?? (typeof document === "undefined" ? "" : document.documentElement?.lang) ?? "").trim();
111
+ };
108
112
  async function post(path, form, bad) {
109
113
  if (bad) return { ok: false, error: { code: bad.code, message: bad.message, field: bad.field } };
110
114
  try {
111
115
  const res = await doFetch(`${base}${path}`, {
112
116
  method: "POST",
113
117
  credentials: "same-origin",
114
- headers: { "content-type": "application/json", accept: "application/json" },
118
+ headers: { "content-type": "application/json", accept: "application/json", ...locale() ? { "x-cauthy-locale": locale() } : {} },
115
119
  body: JSON.stringify(form)
116
120
  });
117
121
  const body = await res.json().catch(() => null);