How to generate User UID at my server using firebase server sdk?

3,443 views
Skip to first unread message

Lam Ha

unread,
Jul 18, 2016, 12:34:40 PM7/18/16
to Firebase Google Group
Hi,

I am trying to login at my server, how to generate unique id look like User UID of firebase?
This is my code.

        @RequestMapping("/login")
public String signInWithCustom(@RequestParam(value = "username") String username,
@RequestParam(value = "password") String password) {
User user = accountManager.login(username, password);
if (user == null) {
     return MessageFactory.createErrorMessage(1000, "User not found");
}

// TODO generate unique id look like User UID of firebase
String userUID = "how";
String token = FirebaseAuth.getInstance().createCustomToken(userUID);
Map<String, Object> params = new HashMap<String, Object>();
params.put("token", token);

return MessageFactory.createMessage(GsonUtils.toGsonString(user), params);
}


Alex Memering

unread,
Jul 18, 2016, 2:08:33 PM7/18/16
to fireba...@googlegroups.com
Firebase uses randomly generated unique identifiers when a new user is created.  Then it always uses that same identifier for that particular user every time.  Since you're using custom authentication you can use whatever string you'd like for the user's UID, however you should take care so that each user's UID is unique to them.  You may want to look into generating a random UUID, generating a random string of alphanumeric characters, or possibly using the user's username.

Hope that helps,
Alex
Engineer @ Firebase

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8d6b391e-0ce4-490c-bb25-aef581d09f9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages