Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

get sub on signup #335

Closed
sehmaschine opened this issue Mar 23, 2017 · 20 comments
Closed

get sub on signup #335

sehmaschine opened this issue Mar 23, 2017 · 20 comments

Comments

@sehmaschine
Copy link

sehmaschine commented Mar 23, 2017

First off, thanks for this library – it's been working great so far.

I have one last issue though: When a user registered, I need to add an entry to my user table with a reference to sub (in order to later get the logged-in user).

If I'm not mistaken, I can only get sub with getUserAttributes which is only possible with an authenticated user. Is there a way to get sub when the user has registered (or confirmed the registration)?

@collinforrester
Copy link

Wondering how to do the same.

seems like it could be put on the response from signUp. Have you found any work arounds?

@aaronelasticmedia
Copy link

@sehmaschine can you describe your use case in more detail?

@sehmaschine
Copy link
Author

@aaronelasticmedia I'm having a database with a user table (and lots of relations to the user). This table has a primary key (ID) and a field sub. I'm mainly using the internal ID in order to reference the user (makes testing and writing fixtures much easier). Therefore, I need to create an entry within that table once a new user registered.

@collinforrester The current workaround is this: Instead of creating the user entry on signup I add the user with the first login. I check if an entry with sub already exists with the internal user table and I create a new entry if it doesn't.

With my API, I'm using the token to get sub and then I query the internal user table to get the user ID. I hope my use case is understandable.

I'm just surprised that signup does return username instead of sub – although sub is the unique value which actually identifies the user.

@itrestian
Copy link
Contributor

We are working on a feature to return the sub on the sign up call. This will be available in the near future.

@sehmaschine
Copy link
Author

@itrestian That's great news. IMO, the unique identifier (sub) should be available with every response with regards to a user (except when I ask for certain attributes specifically).

@jogold
Copy link
Contributor

jogold commented Mar 30, 2017

@sehmaschine why don't you save your internal ID as a custom attribute in Cognito ?

@sehmaschine
Copy link
Author

@jogold Mainly because the registration could fail and then I end up with a user in my database which needs to be deleted (when I create that user beforehand). Doesn't seem like a clean solution IMHO.

@itrestian
Copy link
Contributor

Are you using javascript? Or what is the SDK/language that you are using?

@sehmaschine
Copy link
Author

Yes, javascript.

@SamiSammour
Copy link

@itrestian Is there any news of this feature?

@hemstreet
Copy link

Stumbled upon this little bug today. Any updates?

@rchall-gladly
Copy link

+1 to include the sub in the signup response

@chetanme
Copy link
Contributor

chetanme commented Jun 9, 2017

SignUp API now returns sub in response.

@chetanme chetanme closed this as completed Jun 9, 2017
@MoveLabs
Copy link

The response from Use Case 1 (in README) still does not return userSub.

It seems like /src/CognitoUserPool.js needs an update to explicitly include userSub: data.userSub after line 98:

    var returnData = {
        user: new _CognitoUser2.default(cognitoUser),
        userConfirmed: data.UserConfirmed,
        userSub: data.userSub
    };

As a reminder, User Case 1 is as follows:

    userPool.signUp('username', 'password', attributeList, null, function(err, result){
        if (err) {
            alert(err);
            return;
        }
        cognitoUser = result.user;
        console.log('user name is ' + cognitoUser.getUsername());
    });

Thanks!

@itrestian
Copy link
Contributor

The sub should be available in the newest version.

@gchokeen
Copy link

How can I get this update? I am using aws@1.6.0

@rchall-gladly
Copy link

I'm still not able to get the sub after a signup.
I'm using "amazon-cognito-identity-js": "1.19.0" and "aws-sdk": "2.84.0".
Can someone guide me in the right direction.
This is what I'm getting in my response:

{
  user:CognitoUser
  userConfirmed:true
  userSub:undefined
}

Thanks before hand

@scheler
Copy link

scheler commented Aug 20, 2017

@sehmaschine - once you have 'sub' of the new user how do you pass it to the backend in a reliable way, avoiding fake submissions?

@sehmaschine
Copy link
Author

@scheler We decided to dump cognito in favor of a custom solution (for a variety of reasons). Therefore, I'm not able to answer your question. But if I remember it correctly, we did not pass sub to the backend but used the access token instead. On login we return the user object which contains sub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests