12

I'm trying to set up Cognito to use cookies instead of localStorage for credentials so that I can keep the user logged in between domains, e.g. x.foo.com and y.foo.com. The first step is to get it working on localhost but I'm stuck.

The documentation shows a simple config change should do the trick?

The following debug messages are comitted to the console:

[DEBUG] 37:08.223 AuthClass 
Object { idToken: {…}, refreshToken: {…}, accessToken: {…}, clockDrift: 0 }
ConsoleLogger.js:87

[DEBUG] 37:08.228 Credentials - No Cache module registered in Amplify ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - set credentials from session ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - No Cognito Federated Identity pool provided ConsoleLogger.js:84

[DEBUG] 37:08.230 AuthClass - cannot get cognito credentials No Cognito Federated Identity pool provided ConsoleLogger.js:94

[DEBUG] 37:08.231 AuthClass - Failed to get user from user pool ConsoleLogger.js:84

[ERROR] 37:08.232 AuthClass - Failed to get the signed in user No current user

It seems when you specify the cookieStorage config you need to manually apply a cache instance? How do I do that and will it solve the problem?

Noel Heesen
  • 223
  • 1
  • 4
  • 14

1 Answers1

23

This config works:

{
    region: 'eu-west-1',
    userPoolId: 'eu-west-1_XXXXXX',
    userPoolWebClientId: 'XXXXXX',
    mandatorySignIn: false,
    cookieStorage: {
      domain: 'localhost',
      secure: false,
      path: '/',
      expires: 365,
    },
  }

In particular, secure must be false for localhost unless you are using https (Firefox ignores this for localhost, but Chrome and Safari don't).

zakum1
  • 895
  • 6
  • 20