Closed serjiosilent closed 3 years ago
Any thoughts?
Hi @serjiosilent 👋 I'm curious why you're using aws-cognito-identity-js
separately if it is already a dependency of aws-amplify
? I configured cookieStorage similar to you in my project and did not run into this issue. I used the AmplifyAuthenticator ui component to sign in but this should work the same way if you use the Auth.signIn
method directly.
// index.js
import { Amplify } from "aws-amplify";
import config from "./aws-exports";
Amplify.configure({
...config,
Auth: {
...config,
cookieStorage: {
domain: "localhost",
path: "/",
expires: 365,
sameSite: "strict",
secure: process.env.REACT_APP_AMPLIFY_COOKIE_DOMAIN !== "localhost",
},
},
});
localStorage
cookies
Hi @chrisbonifacio! Thanks for respond. I'm using CUSTOM_AUTH
flow type for password less authentication and I had an error relates on sendCustomChallengeAnswer
method - user.sendCustomChallengeAnswer is not a function
. And using CognitoUser
instance from aws-cognito-identity-js
resolved this issue
@chrisbonifacio I found a bug. I saved user object from response to redux-store and after that put it to sign in, but this user does not have sendCustomChallengeAnswer
method. So, right now I'm saving user object on a temp variable on the code and it works without CognitoUser
instance. Also, removing CognitoUser
fixed issue with cookieStorage. Thanks for point to right direction
oh 😮 I was going to point out this code snippet from the docs on using Auth
library with a custom auth flow
https://docs.amplify.aws/lib/auth/switch-auth/q/platform/js/#custom-authentication-flow
import { Auth } from 'aws-amplify';
Auth.configure({
// other configurations
// ...
authenticationFlowType: 'CUSTOM_AUTH'
});
let challengeResponse = "the answer for the challenge";
Auth.signIn(username, password)
.then(user => {
if (user.challengeName === 'CUSTOM_CHALLENGE') {
// to send the answer of the custom challenge
Auth.sendCustomChallengeAnswer(user, challengeResponse)
.then(user => console.log(user))
.catch(err => console.log(err));
} else {
console.log(user);
}
})
.catch(err => console.log(err));
You can use the sendCustomChallengeAnswer
from the Auth
library and pass in the user returned from Auth.signIn
.
Also, user tokens saving to local storage, not to cookies
I thought so too, but in my case it was because I still had old tokens from previous testing I was doing without cookieStorage
set. Posting this for future readers in case this is your issue. Best way to check is to clear the local storage and try again.
I've tested this a few times and it seems the tokens are always saving to the Cookies storage whenever cookieStorage
is in place, and are saving to local storage otherwise (e.g. when I comment out cookieStorage
).
Loosely related but diverging a bit, it's good to know the pros/cons of cookie vs. local storage.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server amplify-help
forum.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
auth, api
Environment information
Describe the bug
Configured Amplify for using cookieStorage instead localStorage. When I'm trying to login, have an error: "AuthClass - Failed to get the signed in user No current user" Also, user tokens saving to local storage, not to cookies
Expected behavior
Setting up user tokens to cookies and logged in user
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response