Vue Firebase, MySQL & Express

Viewed 24

I am looking to build an app using Vue with Firebase for auth and SQL Server as the db behind Express.

I understand the db workflow will be:

Vue => Express => MySQL

However, when performing the authentication should the workflow be:

Vue => Express => Firebase

or

Vue => Firebase
1 Answers

There are 2 things involved here. Firebase SDKs are meant to be used on client side so you'll have to first sign in user with Firebase Authentication. This way you can easily use security rules for other Firebase services like Firestore, Cloud storage, etc.

To authenticate users on your server (Express application), you can pass current user's token in your API requests as shown below:

const idToken = await auth.currentUser.getIdToken()

await fetch("URL", { headers: { authorization: idToken } })

Then verify the ID Tokens on the backend that should give you the user ID. You can then query your database for user's data and return it.


Alternatively, you can use session cookies so you won't have to pass the token in headers for all requests. Checkout the documentation for more information.

Related