javascript - Angular Auth against Laravel backend -
I am creating an app using Laravel to connect with an Angular Frontend and a small internal API I am creating.
I have a job, but to ensure that this is an acceptable way to enter the user, and to ensure that everything is safe.
Session Controller: Virus root: angular factory: Then I essentially wrap the whole app in something like "app controller" and declare the 'oth' factory as a dependency. Then I can call auth.getAuthStatus () and the user can hide / show things on the basis of the situation because it will be essentially SPA. I know that seeing me / auth / status URI / killed by someone, and wondering how to do it. Like a general question, but any insights will be greatly appreciated. Thank you. Great question I have answered before this one question before I say the same thing . Authentication is slightly different in SPA because you almost completely separate your Larjal app and corner. Laravel takes care of recognition, logic, data, etc. I highly recommend that you read the articles written below. You can use Laravel's route filter to unofficially protect your users. However, since your Larez application has now become only a closing point, it will take heavy load in the form of authentication and authorization to the front frame. Once you set up a root filter, which does not prevent authorized users What do I mean by the examples given above: You have The API endpoint is: / api / v1 / user / 15 9 / edit The endpoint is one of the Restrain 7, and a user can be used to edit. Any software engineer or developer knows that this is a secure endpoint, and if authorized by your application, then send a request with data at that end point. You only want user to be able to perform this action on 159, or administrator. The solution is to those roles / groups / permissions that you want to call them. Set user permissions for your app in your anneller app and archive that data in the token issued possibly. How to properly authenticate / authorize using the front-end JavaScript framework, read this great article (in AngularJS). Article: Public Function Index () {Return Reaction: Jason (Aith :: Check); } Create a public function () {if (Auth :: check ()) {Return Redirect :: to ('/ admin'); } Return Redirect :: From ('/'); } Public Function Login (if (Aith :: Effort (array ('email' = & gt; Input :: JSON ('email'), 'password' = & gt; Input :: JSN ('password')) ) Return (Response Response :: Jason (Ath :: Username); // Return From Direct :: From ('/ Admin');} else {return Answer: Jason (array ('Flash' => Invalid user name or password '), 500);}} Public function logout () {Auth :: logout (); Return response :: Jason (array (' Flash '=>' Log out! ')); }
Root :: find ('auth / statu S ',' session controller @ index ');
app.factory (' at ', ["$ http", function ($ Http) {var Auth = {}; Auth.getAuthStatus = function () {$ http ({method: "GET", url: "/ auth / status", header: {"Content-type": "application / Json "}}. Success (Tasks) {If (data!) {Console.log ('unable to verify auth session');} and if (data) {console.log ('successful status' ); Console.log (data); // Return $ Scope.categories; Auth.status = Data; Return Auth.status;}});} Return Auth;}]);
Comments
Post a Comment