Skip to content
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

Add shared-data for things like auth #1

Closed
tmartin8080 opened this issue Feb 16, 2020 · 12 comments
Closed

Add shared-data for things like auth #1

tmartin8080 opened this issue Feb 16, 2020 · 12 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tmartin8080
Copy link
Collaborator

tmartin8080 commented Feb 16, 2020

Add shared data that will be loaded on every request for auth and other data.

https://inertiajs.com/shared-data

@tmartin8080 tmartin8080 added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Feb 16, 2020
@tmartin8080 tmartin8080 changed the title Add shared-data for different different things like flash Add shared-data for different different things like auth Feb 17, 2020
@tmartin8080
Copy link
Collaborator Author

@zimt28 Any suggestions on how to implement this?

@zimt28
Copy link
Contributor

zimt28 commented Feb 17, 2020

The only sane way I see to get something similar is a function that adds a key/value pair to conn.assigns.inertia_props or similar and InertiaPhoenix.Controller.render_inertia would merge these with regular props. This way data could be added from plugs etc.

@tmartin8080 tmartin8080 changed the title Add shared-data for different different things like auth Add shared-data for things like auth Feb 17, 2020
@tmartin8080
Copy link
Collaborator Author

That makes sense, the developer will just create a custom plug. It's not much different from the way the official rails adapter handles it. Gonna try to stick to their naming of things for consistency.

@bigx333
Copy link
Contributor

bigx333 commented Feb 17, 2020

conn.private should be used for this I believe?:

This storage is meant to be used by libraries and frameworks to avoid writing to the user storage (the :assigns field). It is recommended for libraries/frameworks to prefix the keys with the library name.:

https://hexdocs.pm/plug/Plug.Conn.html#put_private/3

@tmartin8080
Copy link
Collaborator Author

Thanks @bigx333. Good thinking.

Let me know if anyone wants to stab at this.

@zimt28
Copy link
Contributor

zimt28 commented Feb 17, 2020

@bigx333 Yes, much better! Totally forgot about it :)

@zimt28
Copy link
Contributor

zimt28 commented Feb 17, 2020

@tmartin314 On it, will send a PR tomorrow

@tmartin8080
Copy link
Collaborator Author

@zimt28 great! I'll jump on something else

@zimt28
Copy link
Contributor

zimt28 commented Feb 18, 2020

The Laravel implementation uses strings as keys and even allows nesting, eg Inertia::share('auth.user', $user). I guess auth.user will then be used to create something like nested maps (or arrays in PHP?) to allow access via $page.auth.user.name.

I'd prefer atom keys over binary, but we cannot support nesting like Laravel then, which I don't see as an issue. What's your opinion on this, should we support atoms, binaries or both?

@tmartin8080
Copy link
Collaborator Author

tmartin8080 commented Feb 18, 2020

I think we may need to support both as some data might be dynamically generated, but atoms are preferable for sure.

@tmartin8080 tmartin8080 pinned this issue Feb 18, 2020
This was referenced Feb 18, 2020
@tmartin8080
Copy link
Collaborator Author

@zimt28 This was added in v0.2.0

Thanks alot!
cc: @bigx333

@tmartin8080 tmartin8080 unpinned this issue Feb 19, 2020
@zimt28
Copy link
Contributor

zimt28 commented Feb 19, 2020

@tmartin314 Sorry for the missing PR, different time zone and I went to bed first 😄 Thanks for merging the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Development

No branches or pull requests

3 participants