Separated Front & Backend with Tauri
Answered
Gharial posted this in #help-forum
GharialOP
Hey there maybe someone can help with this stupid issue which i got.
First and foremost, english is sadly not my first language so please be patient with my grammar.
What do i want to archive?
- NextJS Frontend & Backend with Nextauth
- Tauri separated instance for the frontend
- Authentication via Nextauth from Tauri (Oauth would be perfect Credentials would be okayish)
What is working:
- NextJS and Nextauth is working with Prisma and mongodb in the background when hosted on the same Node (Docker container export standalone)
What is not working:
Authenticating with nextauth and Tauri
As of now, if you export NextJS with NextAuth as static, you cant obviusly interact with the backend API as there is no "server instance".
So i tried to export the currently working backend and frontend as standalone so it could be deployed to anywhere and almost anything i would want to.
Now to the actual Issue.
When i try to set the envoirement variable for nextauth "NEXTAUTH_URL" to the server/IP with port, it wont use that, but instead "local" api path without the change of the URL applied.
.env
i've also tried to add to the env file:
NEXTAUTH_IDENTITY_SERVER_URL=http://localhost:3001
NEXTAUTH_URL_INTERNAL=http://localhost:3001
So, has anyone expirience with this behaviour, or could direct me further the road?
For some context:
Its a learning project of mine, where worker can enter messurement points from an electrical installation on a clients house/industry.
It then will get saved in the database, and the office people could use either the Tauri Software or the WebUI to interact with the Protocols and archive them.
If you need more info please feel free to ask me, i will share as much as possible.
First and foremost, english is sadly not my first language so please be patient with my grammar.
What do i want to archive?
- NextJS Frontend & Backend with Nextauth
- Tauri separated instance for the frontend
- Authentication via Nextauth from Tauri (Oauth would be perfect Credentials would be okayish)
What is working:
- NextJS and Nextauth is working with Prisma and mongodb in the background when hosted on the same Node (Docker container export standalone)
What is not working:
Authenticating with nextauth and Tauri
As of now, if you export NextJS with NextAuth as static, you cant obviusly interact with the backend API as there is no "server instance".
So i tried to export the currently working backend and frontend as standalone so it could be deployed to anywhere and almost anything i would want to.
Now to the actual Issue.
When i try to set the envoirement variable for nextauth "NEXTAUTH_URL" to the server/IP with port, it wont use that, but instead "local" api path without the change of the URL applied.
.env
NEXTAUTH_URL=http://localhost:3001
NEXTAUTH_SECRET=IchHasseDichUndDeineGanzeGeneration
...i've also tried to add to the env file:
NEXTAUTH_IDENTITY_SERVER_URL=http://localhost:3001
NEXTAUTH_URL_INTERNAL=http://localhost:3001
So, has anyone expirience with this behaviour, or could direct me further the road?
For some context:
Its a learning project of mine, where worker can enter messurement points from an electrical installation on a clients house/industry.
It then will get saved in the database, and the office people could use either the Tauri Software or the WebUI to interact with the Protocols and archive them.
If you need more info please feel free to ask me, i will share as much as possible.
Answered by Ray
I would suggest using the next-auth rest api for authentication on tauri side
23 Replies
GharialOP
Yes
next.config.js
next.config.js
const path = require('path');
const nextConfig = {
output: 'export',
webpack: (config) => {
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(__dirname, './'),
};
return config;
},
};
module.exports = nextConfig;then
next-auth is not gonna workI would suggest using the next-auth rest api for authentication on tauri side
Answer
make a request to
NextJS Frontend & Backend with NextauthGharialOP
But as i've read, you could pass an envoirement variable, so you could separate it.
But if i have to use the RestAPI, is there a somewhat "good" idea, so i could dynamically choose between nextauth native and Rest, so i dont have to create two separated "projects"
But if i have to use the RestAPI, is there a somewhat "good" idea, so i could dynamically choose between nextauth native and Rest, so i dont have to create two separated "projects"
next-auth need to work with api route but api route will not work in static exportwhat do you mean by " create two separated "projects""?
I think you need at least two, one for backend and one for tauri
or use rust backend but you still need two
GharialOP
in theory you could develope the frontend "CSR" for Tauri and Standalone,
@Gharial in theory you could develope the frontend "CSR" for Tauri and Standalone,
yes but you gonna need a backend for authentication
GharialOP
ofc only if you go csr only and go oldschool and develope a heavy API or source it out to rust as functions... Which now i will have to do
Yes Ofc, Think of it like the old shoold aproach
Standalone Nextjs with nextauth --> Wroking perfectly currently this way
Now as this is CSR, you can compile it as static for the frontend and set the envoirement for backend API interface (Same NextJS instance as the Standalone)
Standalone Nextjs with nextauth --> Wroking perfectly currently this way
Now as this is CSR, you can compile it as static for the frontend and set the envoirement for backend API interface (Same NextJS instance as the Standalone)
But this is only working if the entire frontend is Client side Rendered and the API is commonly accessed trougth the API itself.
standalone and static export is two different thing
next generate the output for node in standalone build
and generate html only for static export
and generate html only for static export
GharialOP
yes
so if you use rest api on tauri side, you don't need
next-auth package on the tauri sideGharialOP
true, i will just separate them entirely and may implement the authentication on the rust side. will be also a good learning experience
@Gharial true, i will just separate them entirely and may implement the authentication on the rust side. will be also a good learning experience
yep and the reason why the env variable not work is your were using static export mode and reading it on client side without
NEXT_PUBLIC_ prefixGharialOP
AAh Okay