PROBLEM: UserSession UserData managed as Global State

Hi everbody,

recently I am starting with React and Blockstack and there are a lot of wonderful ressources like Techrally and the team around banter and lettermesh.
At the moment I face problem with setting a Global-State for the UserData. This global state is provided by a React Context.

Currently I construct the UserSession, but for example the methods isUserSignedIn() or loadUserData() dont work as expected on the Session attribute of the state.
Especially the function for the useReducer hook is not working:

const makeUserSession = (state) => {

    const session = state.userSession
    const auth = session.isUserSignedIn();
    const data = session.loadUserData();
    // console.log(data)
    switch (auth) {
        case true:
        const data = session.loadUserData();
        const name = data.username;
            return {...state, userData: data, userName: name, userAuth: auth};

        case false:
            return {...state, userAuth: auth}

        default:
            return {...state, userAuth: auth}
    }
}

If there is someone who has few spare minutes, it would be great if you look at the github repository --> Lexar and share your thoughts.
I am using next.js at the moment. Thanks :slight_smile:

Hi chaincontact,

Here are some hints, how to fix your issue:

  • you must not call loadUserData() if the user is not signed in.
  • you must call handlePendingSignIn in order to sign in.
  • you best make your makeUserSession an async function.

I sent you a pull request: https://github.com/Chipandcharge/lexar/pull/1

1 Like

HI friedger,

thanks for you effort and the thoughts. Something strange happend in the UserReducer file and the context provided. After getting returning data from the makeUserSession() the context provided a object with weird namevaluePairs. These pairs had the names _a, _b, … and _y then held the write data.
Anyways I just pulled the the logic out of the function into the case block.

:ok_hand:t4: