-
Notifications
You must be signed in to change notification settings - Fork 971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Firebase to the AuthClients #593
Adding Firebase to the AuthClients #593
Conversation
Conversation thread in forums here: |
Thanks a lot for your 2ç @thedavidprice ;), I'm fully migrating the conversation here - if it's ok. @peterp I'm pinging you, I don't want to take decisions on the matter, I'm happy to offer my own 2ç ( so far makes a piggy of 4ç! ) and happy to extend my PR, but I'd need some directions to make sure what I'd propose follows RW's line and the community's interests. Picking up where @thedavidprice lead us: 2. Identity Providers I'd vote to offer a very rudimentary default - this one seems to work, and figure out how to make it possible for the end user to implement the complexity they want, as you suggest, since Firebase offers plenty. @peterp what would be your stand here? 3. FirebaseUI 4: Documentation 5. RW Auth Generator |
That sounds reasonable. In the future, I think we could add a way to "pick" the auth provider, but I guess we need to be certain that the other methods work for those providers. Picking a provider could look something like: login: async (provider = "GoogleAuthProvider") => {
const provider = new client.auth[provider]()
return client.auth().signInWithRedirect(provider)
}, What kind of token does this push onto the api side? |
@peterp agreed, it requires a thorough verification before. The token is encoded, I decoded it in auth.js:
I have to move it ( the The token provides a user object with the following keys: 'name', |
That's fine. That's the approach that we've taken with |
@peterp what would be missing to have it merged in a first version? |
Hey @noire-munich - I'll put this into my review queue, it should be merged this weekend :) |
CoverageThe PR is very straightforward, it offers only a sign up with redirect feature, it lets Google take on the entire process ( display & events ). It doesn't cover:
|
Does this allow signup with email/password or only the googleAuth? |
@redwoodjs/auth also can't be found.
|
@AWey95 It doesn't at the moment, but you could use Netlify identity for that. Check out this guide for how to get started with authentication: https://redwoodjs.com/docs/authentication |
Would this force me to use their own premade UI or can I stick with the design I already have? I would rather not have any popups or email links to get this working. |
Hey @AWey95, so you're already using Firebase? And you want to use your own UI to instead of the pop-up? |
That's correct. I would rather not use a pop-up so I can keep my design consistent throughout. The pop-up is fine for google/github auth but if someone is authenticating with email/password I want them to use my form. I haven't used Firebase with redwoodjs yet. I have used their auth system before though. |
Pull request draft, There are a couple of todos to get it to work.
Otherwise dirtily tested in a project, seems to work properly.
Firebase Authentication
The Firebase authentication will require you to register your application to the firebase console - it's not as long as it sounds, everything is detailed in the official documentation: https://firebase.google.com/docs/web/setup
Once you are done it is time to write some code.
In web/src/index.js, make sure to have these lines:
(You will find the below snippet in the Firebase console, Project settings > General Parameters )
We have setup the AuthClient for RedwoodJS, this means that we can now use the
useAuth()
hook from RedwoodJs. But we are not done yet, as we still need to change an important file on the API side.If it doesn't exist, add
api/src/lib/auth.ts
and consider this implementation of the much neededgetCurrentUser
function:Now make sure that you pass this
getCurrentUser
to thecreateGraphQLHandler
inapi/src/functions/graphql.js
:And you should be good to go.
In your services you will be able to fetch your current user using this import:
import { context } from '@redwoodjs/api'
. It will have the type of whichever data you are sending back from thegetCurrentUser
function.