Replies: 2 comments 2 replies
-
Lemme attempt to answer the questions.
Question is little vague. Infact, there is no direct answer to it, as an application has many layers and based a lot on which layer goes down.
Yes, you can. A single app can use multiple guards. I myself will use API guard for the mobile app and web guard for web app
With this I assume that your web app returns HTML (by rendering edge views) from the server itself. In other words, it is not a frontend SPA written in Vue or React. Sharing code is again can be done in multiple ways. The simplest one is use content negotiation. For example: // Fetch data as normal
// Then use the switch case to choose the response type
switch (request.accepts(['html', 'json'])) {
case 'html':
return view.render()
case 'json':
return dataAsJSON
} Now make sure that your mobile app adds |
Beta Was this translation helpful? Give feedback.
-
@thetutlage I need one last answer please 🙂 |
Beta Was this translation helpful? Give feedback.
-
Hi ! (Sorry if some sentences aren't correct, I'm french !)
So the title is my question. I want to build a web app, a mobile app (the same project) and I want an API server to give the auth and the data from database.
If one day I have a problem with the website, and the api is hosted on this website, I don't want mobile user was unable to use the app, that why the api server is outside of that.
Following the AdonisJs doc, API Guard should be the best solution for using auth with a mobile app.
My question is, am I doing it right ? For auth my users from the website, what is the best way to store the generated token from api guard ? It is unsafe to store it in a cookie ?
Can/Should I use a mix web guard / api guard ? ex.: web guard for the website and api guard for mobile app ?
Can I simply share code between API server and my website to populate object/class from json data ?
You are all welcome to give your opinion, thank you !
Beta Was this translation helpful? Give feedback.
All reactions