petrpavlik/vapor-saas-backend-template

User registration

ladiesman218 opened this issue · 3 comments

I have no experience nor knowledge for firebase at this moment. But do get one question, about the registration logic:
do I have to get an firebase JWT token before I can register an account for a SaaS service?
I sense this could be a stupid question, but could really use some help here..

This template outsources user management to a 3rd-party service, Firebase Authentication in this case. Every request in the code is expected to receive a JWT token in the header, which is verified and decoded into object we can pull user identity from (email, name and avatar when available). https://github.com/petrpavlik/vapor-saas-backend-template/blob/main/Sources/App/Controllers/ProfileController.swift#L61

Calling POST /profile validates and decodes the JWT token containing the user email with other metadata (name, avatar url) and creates or updates the user (profile) in postgres.

Then there's this convenience extension to fetch a user profile from a request handle https://github.com/petrpavlik/vapor-saas-backend-template/blob/main/Sources/App/Controllers/ProfileController.swift#L7

All auth providers (firebase auth, amazon congnito, ...) work pretty much the same way and I could do a better job abstracting firebase to make it a bit easier to switch to something else, but it's all just about updating these 2 places really.

You'll need to use a firebase SDK for whatever you're using for your frontend or the firebase rest API (which is being used for unit tests here to simulate a frontend) to authenticate a user and receive their JWT token that you'll send with every request to the backend.

Here's a tutorial for iOShttps://www.youtube.com/watch?v=q-9lx7aSWcc. You'll find similar torials for the web (react, ...), android, or whatever you're using for your frontend.

Hope this makes sense.

Could you provide the specification for how to create a user in postman? API endpoint, http method and request data, etc.
I can't get it work

I've made some changes to the code and exposed sample credentials that can be used in .env.testing file. See more in this reply please #7 (comment)