"No current user" from currentSession() AWS Amplify and Cognito

Viewed 2041

I am trying to get a REST API to return currentSession() from AWS Amplify and Cognito. The SignIn function works and i get a CognitoUser object returned, however, the getSession() function returns "No current user"

const Amplify = require('aws-amplify');
const express = require('express');
const router = express.Router();

Amplify.default.configure({
    Auth: {
        region: 'REGION',
        userPoolId: 'USERPOOLID',
        userPoolWebClientId: 'WEBCLIENTID',
        authenticationFlowType: 'AUTHTYPE',
    }
  })

router.post('/', (req, res) => {
    async function signIn(username, password) {
        try {
            Amplify.Auth.signIn(username, password)
                .then(() => getSession())
                .catch(err => console.log(err));
        } catch (error) {
            res.json(error);
        }
    }

    async function getSession() {
        try {
            Amplify.Auth.currentSession()
                .then(data => console.log(data))
                .catch(err => console.log(err));
        } catch (error) {
            res.json('error');
        }
    }

    signIn(req.body.u, req.body.p);
});

Help!

0 Answers
Related