MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / fetchSessionUser

Function fetchSessionUser

client/src/redux/fetch-user-saga.js:13–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11} from './actions';
12
13function* fetchSessionUser() {
14 const timeoutTask = yield fork(function* () {
15 // The server should not take anywhere near 2 seconds to respond. If it
16 // does, we assume the request has failed and dispatch a timeout action to
17 // dismiss the loading state.
18 yield delay(2000);
19 yield put(fetchUserTimeout());
20 });
21
22 try {
23 // This is on a longer timeout to make sure that users with slow connections
24 // do, eventually, get signed in.
25 const res = yield call(getSessionUser, AbortSignal.timeout(10000));
26
27 const isSignedOut = res.response.status === 401;
28 if (!res.response.ok && !isSignedOut) {
29 throw new Error(
30 `HTTP Error: ${res.response.status} ${res.response.statusText}`
31 );
32 }
33
34 const { data: user } = res;
35 yield put(fetchUserComplete({ user }));
36 } catch (e) {
37 console.log('failed to fetch user', e);
38 const handledError = wrapHandledError(e, UserFetchErrorMessage);
39 yield put(fetchUserError(handledError));
40 } finally {
41 yield cancel(timeoutTask);
42 }
43}
44
45function* fetchOtherUser({ payload: maybeUser = '' }) {
46 try {

Callers

nothing calls this directly

Calls 3

wrapHandledErrorFunction · 0.90
putFunction · 0.85
delayFunction · 0.70

Tested by

no test coverage detected