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

[2.x] Inertia.js: Add support for all Jetstream-provided views. #298

Merged
merged 12 commits into from
Oct 7, 2020
Merged

[2.x] Inertia.js: Add support for all Jetstream-provided views. #298

merged 12 commits into from
Oct 7, 2020

Conversation

claudiodekker
Copy link
Contributor

This PR adds Inertia variants for all Jetstream included views. This allows a more native Inertia experience for users of this stack, and solves several issues and difficulties that makes for an all-in-all smoother experience.

For example, some Jetstream users have been asking questions on our Discord regarding difficulties they're experiencing with getting Jetstream to play well with Inertia. Specifically, the most common issue is when a session expires, as the user then gets redirected to the login page, and because that login page is a Blade view, Inertia renders it in a so-called 'error modal'.

To solve or prevent this, users should instead use Inertia for their login pages as well, and while some have gotten to the point where they're attempting to (re)configure Fortify to use Inertia views instead, this too isn't the most straight-forward thing to do.

@reinink
Copy link
Contributor

reinink commented Oct 2, 2020

@taylorotwell For what it's worth, I definitely think this is the right approach to go. The best Inertia.js experience is to do your whole app with Vue based page components. Session expiration "just works" this way, since users are automatically redirected back to the login page, which itself is an Inertia endpoint. I don't think I'd ever, personally, build an app that had a mix of Blade views and Vue page components. That said, this does create an extra maintenance burden on this project, since these auth views can no longer be shared between the two stacks. I feel like that's a worthwhile tradeoff though. 🤷‍♂️

That all said, the session expiration issue could be solved using an Inertia::location($url) (409) response that's called in the authentication middleware. This would force a "full page redirect" to the login page. To me this is more of a band-aid, and I'd again prefer the solution in this PR. 👍

@claudiodekker Excellent work brother, this looks great. 🙌

@claudiodekker
Copy link
Contributor Author

claudiodekker commented Oct 2, 2020

Thanks! 👍

On a side-note (just so that I don't forget), Once laravel/fortify#107 gets tagged, I can remove the ->toResponse($request) calls from this PR as well. Since it hasn't yet, I've decided to leave them in for now.

@reinink
Copy link
Contributor

reinink commented Oct 2, 2020

Yup, and while we're creating todo lists, it would be great to get @inertiajs/inertia on v0.3.0, and then update all the Jetstream code to use the new event callbacks. When we make that change, we should add @inertiajs/progress to the project, since right now there isn't any loading indicators, since the NProgress CSS isn't included.

@driesvints driesvints changed the title Inertia.js: Add support for all Jetstream-provided views. [2/xInertia.js: Add support for all Jetstream-provided views. Oct 5, 2020
@driesvints driesvints changed the title [2/xInertia.js: Add support for all Jetstream-provided views. [2.x] Inertia.js: Add support for all Jetstream-provided views. Oct 5, 2020
@taylorotwell
Copy link
Member

@claudiodekker I've just tagged a new laravel/fortify release.

This is no longer necessary as of Fortify 1.6.1
@claudiodekker
Copy link
Contributor Author

claudiodekker commented Oct 5, 2020

@taylorotwell Thanks! I've updated the PR. I also updated the composer.json to reflect the minimum Fortify version to be ^1.6.1 so that this PR is guaranteed to work, but let me know if you'd rather leave that unchanged.

Since 'filled' is used in the back-end, using remember: false will cause remember to pass.
@@ -0,0 +1,8 @@
<template>
<a href="/">
<svg class="w-16 h-16" viewBox="0 0 48 48" fill="none" xmlns="http:https://www.w3.org/2000/svg">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just reuse the ApplicationMark component here instead of duplicating?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I looked at that, but it's different, and because I'm trying to replicate the other views to keep branding consistent I copied this one instead.

@taylorotwell
Copy link
Member

@claudiodekker Does this need to be rebased or something? It seems to contain some random other commits?

@claudiodekker
Copy link
Contributor Author

claudiodekker commented Oct 6, 2020

@taylorotwell Yeah, I merged 1.x into it, as that contains @m1guelpf's Ziggy PR changes.. As a result, master is behind on those changes.

@taylorotwell
Copy link
Member

I've merged 1.x into master.

@claudiodekker
Copy link
Contributor Author

@taylorotwell Fixed, thanks! 👍

@taylorotwell
Copy link
Member

Sick. Will probably review and get this merged in tomorrow.

@claudiodekker
Copy link
Contributor Author

claudiodekker commented Oct 6, 2020

Cool, let me know if there's anything else you need me to do 👍

@taylorotwell
Copy link
Member

@claudiodekker One bug I've noticed so far... on two-factor code entry screen after login... entering the code and then hitting "enter" just toggles you to recovery code form instead of submitting auth code.

@claudiodekker
Copy link
Contributor Author

Oof, yeah, that shouldn't happen.

I'll look at it in a bit, and will also double check the keyboard behavior of other forms.

@taylorotwell
Copy link
Member

That was the only thing I hit so far. I think I've tested every form.

@claudiodekker
Copy link
Contributor Author

Great, thanks for letting me know! 🙏

Having dinner right now, so it might take an hour or so before I have a fix. Want me to ping you when it's done?

@taylorotwell
Copy link
Member

I think I'l have it fixed. Don't worry about it.

},
methods: {
toggleRecovery() {
this.recovery ^= true
Copy link
Contributor

@m1guelpf m1guelpf Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.recovery ^= true
this.recovery = ! this.recovery

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are using this to toggle between 0 and 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be less confusing to use a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually correct. It's a bitwise XOR that changes true to false, and false to true in this situation (hence toggle) 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a neat trick!

Copy link
Contributor Author

@claudiodekker claudiodekker Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure 🙂 Also works in PHP, or any other C-based language for that matter AFAIK 👌

</div>

<div class="flex items-center justify-end mt-4">
<button @click.prevent="toggleRecovery" class="text-sm text-gray-600 hover:text-gray-900 underline cursor-pointer">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<button @click.prevent="toggleRecovery" class="text-sm text-gray-600 hover:text-gray-900 underline cursor-pointer">
<button type="button" @click.prevent="toggleRecovery" class="text-sm text-gray-600 hover:text-gray-900 underline cursor-pointer">

Use an authentication code
</template>
</button>
<jet-button class="ml-4" :class="{ 'opacity-25': form.processing }" :disabled="form.processing">

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already the default type for jet buttons.

@taylorotwell taylorotwell merged commit e25e36d into laravel:master Oct 7, 2020
@claudiodekker claudiodekker deleted the inertia-auth-support branch October 7, 2020 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants