As I needed to authenticate the user of an app, I’ve chosen for something the most straightforward possible, so I thought using Firebase would be a good fit.
So, I ran into the docs (I’m skipping the prerequisites here for the sake of concision):
Create a password-based account
Sign in a user with an email address and password
Handle the sign-in flow with the Firebase SDK
So I succeed to send an authentication request with login/pass and Google.
So now, correct me if I’m wrong, but, I think I need to make the following steps:
-
Pass a session_ID to my back-end (a svelte endpoint call by a classic http post request I suppose).
-
Then, the back-end can store the session_ID in a database associated with the corresponding user_ID
-
Call a function on each private page of the back-end that will check if the session_ID provided by the front-end exists, then serve the page or redirect the user.
The thing is … I get a huge object back from Firebase Auth and I have to confess that I’m a little lost here… You can see below what I get back when I sign-in with an account using both login/pass and Google authentication.
Which ID am I supposed to take as a session_ID and which one as a user_ID ?
I can see:
accessToken & refreshToken in the stsTokenManager property
accessToken & refreshToken in the credential property
idToken
uid or Google auth
uid for login/Pass auth
uid for I don’t know (see “proactiverefresh”)
federatedId
rawId
localID
…
Thank you for your help 🙂
{
"providerId": "firebase",
"emailVerified": true,
"isAnonymous": false,
"tenantId": null,
"providerData": [
{
"providerId": "google.com",
"uid": "100373089962418343181", <--------
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
},
{
"providerId": "password",
"uid": "[email protected]", <--------
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
}
],
"proactiveRefresh": {
"user": {
"uid": "qEOrRfkIkyMgqHNaRvABPKf2WTZ2", <--------
"email": "[email protected]",
"emailVerified": true,
"displayName": "Robert Smith",
"isAnonymous": false,
"photoURL": null,
"providerData": [
{
"providerId": "google.com",
"uid": "100373089962418343181",
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
},
{
"providerId": "password",
"uid": "[email protected]",
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
}
],
"stsTokenManager": {
"refreshToken": "XjoPcMzMi ...IAKI",
"accessToken": "iuJhbGciOiJSUzI1NiI ... Sj1AcJGpsUw",
"expirationTime": 1647453201017
},
"createdAt": "1632145000204",
"lastLoginAt": "1647449600973",
"apiKey": "EIzaDyACBh...q7YYrBB",
"appName": "[DEFAULT]"
},
"isRunning": false,
"timerId": null,
"errorBackoff": 30000
},
"reloadUserInfo": {
"localId": "qEOrRfkIkyMgqHNaRvABPKf2WTZ2", <--------
"email": "[email protected]",
"displayName": "Robert Smith",
"photoUrl": null,
"passwordHash": "AiVEOFJURDZ=", <-------- ??
"emailVerified": true,
"passwordUpdatedAt": 1647445046758,
"providerUserInfo": [
{
"providerId": "google.com",
"displayName": "Robert Smith",
"photoUrl": null,
"federatedId": "100373089962418343181",<--------
"email": "[email protected]",
"rawId": "100373089962418343181"<--------
},
{
"providerId": "password",
"displayName": "Robert Smith",
"photoUrl": null,
"federatedId": "[email protected]",<--------
"email": "[email protected]",
"rawId": "[email protected]"<--------
}
],
"validSince": "1647445046",
"lastLoginAt": "1647449600973",
"createdAt": "1632145000204",
"emailLinkSignin": true,
"lastRefreshAt": "2022-03-16T16:53:20.973Z"
},
"reloadListener": null,
"uid": "qEOrRfkIkyMgqHNaRvABPKf2WTZ2",
"auth": {
"apiKey": "EIzaDyACBhHedUIhOIXiTjfipSWOlxZIq7YYrBB",
"authDomain": "test-project-999999.firebaseapp.com",
"appName": "[DEFAULT]",
"currentUser": {
"uid": "qEOrRfkIkyMgqHNaRvABPKf2WTZ2",
"email": "[email protected]",
"emailVerified": true,
"displayName": "Robert Smith",
"isAnonymous": false,
"photoURL": null,
"providerData": [
{
"providerId": "google.com",
"uid": "100373089962418343181",
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
},
{
"providerId": "password",
"uid": "[email protected]",
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null
}
],
"stsTokenManager": {
"refreshToken": "XjoPc...IAKI",
"accessToken": "iuJh...psUw",
"expirationTime": 1647453201017
},
"createdAt": "1632145000204",
"lastLoginAt": "1647449600973",
"apiKey": "EIzaDyACBhHedUIhOIXiTjfipSWOlxZIq7YYrBB",
"appName": "[DEFAULT]"
}
},
"stsTokenManager": {
"refreshToken": "XjoPc...IAKI",<--------
"accessToken": "iuJh...psUw",<--------
"expirationTime": 1647453201017
},
"accessToken": "iuJh...psUw",<--------
"displayName": "Robert Smith",
"email": "[email protected]",
"phoneNumber": null,
"photoURL": null,
"metadata": {
"createdAt": "1632145000204",
"lastLoginAt": "1647449600973"
},
"credential": {
"idToken": "eyJhbGciOi...nMI-ciozQ",<--------
"accessToken": "ya29.A0AR...9qXUQ",<--------
"pendingToken": null,
"providerId": "google.com",
"signInMethod": "google.com"
}
}