Redwood: Generators: Add auth generator for Magic.Link

Created on 29 May 2020  路  16Comments  路  Source: redwoodjs/redwood

Now that support for Magic.Link has been added to @redwoodjs/auth as of 0.8.0 we can add a generator that helps setup and configure this automatically.

Take a look at the existing providers and the README to see how to add Magic.Link support. If you need additional hooks to insert generated code into you will need to modify the auth generator itself.

good first issue kinimprovement generators

All 16 comments

Hi, I'd like to work on this if no else has started. I'm new here, I've just finished the tutoral and browsed the framework code. I'd also like to say, I really like the vision of this project. Cheers

Great! I'll assign this one to you. Definitely look to @cannikin as point for help along the way with the generators. For any Auth specific instructions, @peterp created the original package and @Burnsy did the provider work on Magic.Link.

Oh, and I'm the annoying guy who will show up at the very end to ask if the PR includes updated documentation 馃槈 (Everyone has their role, right?)

Looking forward to this one 馃殌

Ok great!, Thanks for the detailed reply @thedavidprice

I don't mind giving a hand if needed! 馃憤

@cannikin or @Burnsy I'm having trouble generating the correct import statement for magic.link. It needs to create {} around the inport i.e. .. import { Magic } from 'magic-sdk'... right now it does not, it generates import Magic from 'magic-sdk.
I see that for the auth0, brackets were used in the import statement but not in the case of netlify-identity.
Any quick tips, maybe i'm missing something obvious , before I dive into the generator code?

Did you try doing:

imports: [{ import: '{ Magic }', from: 'magic-sdk' }]

The code that writes out the import does:

const importStatements = imports.map((imp) => {
  return `import ${imp.import} from '${imp.from}'`
})

So it should include the {} as long as they're inside that first string.

@cannikin no I didn't, because the auth0 provider, which generates brackets, isn't Implemented that way . I'm wondering how it was accomplished in that case. Anyway,I will try your suggestion thanks!
Secondly, should I add any generated code to the back-end. e.g. https://redwoodjs.com/docs/authentication#magic-links
or would that be a seperate pull request

That might be a bug鈥攊f auth0 requires { } around the import then that generator should definitely have them!

When you refer to the back-end are you talking about the code in api/src/lib/auth.js? getCurrentUser is meant to be specific to your own application's idea of what a user is, so I we can't pre-fill that with anything other than the default鈥攋ust returning what the auth provider provides. It's up to you to figure out what you need from that to look up and return a user from your data store.

@cannikin Ok thanks, that makes sense.
@thedavidprice Where/How do I update the docs. Is it just changing the readme files in the monorepo?

Opened a PR to fix that auth0 import! https://github.com/redwoodjs/redwood/pull/640

There are a few things in motion with docs as we are in a bit of a re-org. So most of the docs are or will be in this /docs folder on the .com repo.

But you are correct --> currently the Auth doc is the README in the auth package. For the generator, it looks like you'll primarily need to update the "Installation" section both for available providers and the Manual Install of Magic.Link (assuming a package would need to be added).

AND you'll also need to add the provider option to this section of the CLI Docs. This Doc correlates with the information you should see when you run yarn rw g auth --help.

Lots of bits and pieces, but is it making sense?

Thanks again!

@thedavidprice the second link you left is broken. Can you give a path, I can't seem to find it

@thedavidprice I'm unclear as how to edit the docs in the redwood.js repo within this pull request.
Isn't the redwoodjs.com a seperate repository from the redwood repository? Can I update redwood.js/blob/master/docs in a seperate pull request?
I'm a little new to this
Thanks in advance

Ah, great question! And you may _feel_ new, but trust me, we're all relatively new and figuring things out as we go. Together. So welcome to the party 馃帀

Yes, you'll need to handle that separately on the redwoodjs.com repo. That doc was created by @jtoar who I'm sure would be happy to help if/when needed.

Overall we're just trying to get better at including doc creation/update with PRs. But sometimes that might simply mean creating an Issue with a plan and making a handoff by asking for help. Whatever steps you're able to take, just reference the other Issues or PRs via links to the main Issue or PR -- that way we can allow follow the trail, connect dots, and quickly see what next steps might need to be completed.

@thedavidprice Ok, Thanks again. I'll do that.

Was this page helpful?
0 / 5 - 0 ratings