MVC/SPA Routing Hybrid

I was hoping more experienced programmers could give some insight on this topic.

Basically, I have been fiddling around with an .NET Core Web Api project using VueJS as my JavaScript framework. One of the things that has been tripping me up is using JWTs for role-based authentication. To be honest, I find the implementation messy and cumbersome and hard to keep up with.

What I ended up doing was build out an MVC app. Each controller has an Index method (with Route attributes to handle any potential routes that would get hit pertaining to that controller, for example: [Route(“”)] and [Route(“Customer/Edit/{id?}”)]). That Index method returns a view, which is nothing more than a blank Razor view that points to _Layout. _Layout is where the bundled JavaScript files from webpack are referenced.

In the end, a user navigates to a page. ASP.NET picks up the route, hits the Index, and returns the blank Razor page. At this point, VueJS’s router picks up the route and does it’s front end stuff. After that, any calls to the server are typical POSTs or GETs – like hitting an API.

On terms of authorization, I am using .NET Core Identity and cookie-based authentication. Controllers that are locked behind the [Authorize] attribute redirect to Account/Login, which is handled strictly in MVC/Razor pages. None of the authentication code is in VueJS.

My question is, is this strange? Unnecessary? Am I making a convoluted mistake by building my app out this way?

submitted by /u/a_third_programmer
[link] [comments]

Leave a Reply