AWS Cognito cookie storage
Asked Answered
D

1

14

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?

Docila answered 19/12, 2019 at 11:49 Comment(0)
L
27

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).

Linage answered 29/6, 2020 at 20:41 Comment(1)
Legend! Just adding the cookieStorage part worked for me!Boesch

© 2022 - 2024 — McMap. All rights reserved.