@ya-accelerators/nextjs-framework 0.0.108 → 0.0.109
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.
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useRouter } from 'next/navigation';
|
|
3
3
|
import { signOut } from 'next-auth/react';
|
|
4
|
-
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { useLoadingContext } from '../../../hooks/loading';
|
|
6
6
|
import { deleteCookieValue, getAllCookieNames } from '../../../lib/cookie';
|
|
7
|
+
import { logger } from '../../../logger';
|
|
8
|
+
import { ErrorPage } from '../errorPage';
|
|
7
9
|
export const SignOutForm = ({ replace }) => {
|
|
8
|
-
const { showLoading } = useLoadingContext();
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
showLoading();
|
|
11
|
-
}, [showLoading]);
|
|
10
|
+
const { showLoading, dismissLoading } = useLoadingContext();
|
|
12
11
|
const router = useRouter();
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const [failed, setFailed] = useState(false);
|
|
13
|
+
// LoadingProvider rebuilds showLoading / dismissLoading on every render of its own, and showLoading is
|
|
14
|
+
// what makes it render, so a callback closing over them changes identity on each run. The ref keeps the
|
|
15
|
+
// sign-out reachable from the retry without putting that identity in a dependency list, where it would
|
|
16
|
+
// re-fire the effect below and sign out in a loop.
|
|
17
|
+
const runRef = useRef(async () => { });
|
|
18
|
+
runRef.current = async () => {
|
|
19
|
+
showLoading();
|
|
20
|
+
const allCookieNames = await getAllCookieNames();
|
|
21
|
+
await Promise.all(allCookieNames.map((cookieName) => deleteCookieValue(cookieName)));
|
|
22
|
+
// The session cookie is httpOnly, so the loop above cannot reach it and this call is the only thing
|
|
23
|
+
// that ends the session. Navigating away on a failure would leave it live while the UI reports the
|
|
24
|
+
// user as signed out, so the failure is surfaced and the page stays put.
|
|
25
|
+
const failure = await signOut({ redirect: false }).then(() => undefined, (error) => error);
|
|
26
|
+
if (failure !== undefined) {
|
|
27
|
+
// The retry surface is put up before the record is written: the logger reads the client env on its
|
|
28
|
+
// first call, so a package missing NEXT_PUBLIC_DEPLOY_ENV throws here and would otherwise leave the
|
|
29
|
+
// page under the loading overlay with no way forward.
|
|
30
|
+
dismissLoading();
|
|
31
|
+
setFailed(true);
|
|
32
|
+
logger.error('auth', { error: failure });
|
|
16
33
|
return;
|
|
17
34
|
}
|
|
18
|
-
|
|
35
|
+
setFailed(false);
|
|
36
|
+
router.refresh();
|
|
37
|
+
router.replace(replace === undefined ? '/' : replace);
|
|
38
|
+
};
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
void runRef.current();
|
|
19
41
|
}, []);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await signOut({ redirect: false }).catch(() => undefined);
|
|
25
|
-
router.refresh();
|
|
26
|
-
router.replace(replace === undefined ? '/' : replace);
|
|
27
|
-
}}/>);
|
|
42
|
+
if (failed) {
|
|
43
|
+
return <ErrorPage reset={() => void runRef.current()}/>;
|
|
44
|
+
}
|
|
45
|
+
return <></>;
|
|
28
46
|
};
|
|
29
47
|
//# sourceMappingURL=index.jsx.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../../../../src/ui/functional/signOutForm/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../../../../src/ui/functional/signOutForm/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,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