by using process.env.NEXT_PUBLIC_ANALYSTICS_PASSCODE will anyone be able to see my code value?
Unanswered
Ashy Storm-Petrel posted this in #help-forum
Ashy Storm-PetrelOP
hello i want to upload website and make like admin panel so i want to add this to the frontend so i can verify form login (only for one person to access)
35 Replies
@Ashy Storm-Petrel hello i want to upload website and make like admin panel so i want to add this to the frontend so i can verify form login (only for one person to access)
yes, adding the NEXT_PUBLIC prefix will expose your env secret to the client, browser
@Dayo yes, adding the NEXT_PUBLIC prefix will expose your env secret to the client, browser
Ashy Storm-PetrelOP
what's the best approach?
rather than call the API directly in your frontend, create an API route and use your env variable without the NEXT_PUBLIC prefix inside
then call your api in your frontend as in /api/auth
then call your api in your frontend as in /api/auth
that way, your secret will remain on the server
@Dayo rather than call the API directly in your frontend, create an API route and use your env variable without the NEXT_PUBLIC prefix inside
then call your api in your frontend as in /api/auth
Ashy Storm-PetrelOP
yah i did that but what i'm looking for is little login page that sends a API request with my secret passcode to the backend + to have like password that stored in the frontend to verify
i know it's not good approach but it's only 1 user who should be able to be able to do these stuff
i know it's not good approach but it's only 1 user who should be able to be able to do these stuff
@Ashy Storm-Petrel yah i did that but what i'm looking for is little login page that sends a API request with my secret passcode to the backend + to have like password that stored in the frontend to verify
i know it's not good approach but it's only 1 user who should be able to be able to do these stuff
well, you’ll probably have to add the secret to your api route and then compare that the password in your post request in your login form is the same as the one you hardcoded in your api route
@Dayo well, you’ll probably have to add the secret to your api route and then compare that the password in your post request in your login form is the same as the one you hardcoded in your api route
Ashy Storm-PetrelOP
Yah i did do that but I'm wondering will someone looking in the code would know the value
@Ashy Storm-Petrel Yah i did do that but I'm wondering will someone looking in the code would know the value
oh okay. from your implementation, yes
Ashy Storm-PetrelOP
yah so i'm wondering what's the best approach to change the NEXT_PUBLIC_ANALYSTICS_PASSCODE or is there a better way?
rather than pass the env to your form, why not add a field where you can type the password out
and in your api route use the env without the prefix
and in your api route use the env without the prefix
@Dayo rather than pass the env to your form, why not add a field where you can type the password out
and in your api route use the env without the prefix
Ashy Storm-PetrelOP
there will be that but i want requests to post/delete/edit only come from that website endpoint if their passowrd and username is correct
so for example if someone try to make delete request and they don't know the passcode their request will be denied
or is there better approach to not let any request come from outside the website?
@Ashy Storm-Petrel or is there better approach to not let any request come from outside the website?
yes i believe you can use a middleware for that
i haven’t used it much since Next 13 but i’m sure you’ll find sth useful in the docs
Ashy Storm-PetrelOP
the new docs are hurting my brain lol and since the newsest update doesn't have much content about it it's little hard
sorry bout that
is there a reason you’re not using a database for this though? like a simple google auth with firebase/supabase?
Ashy Storm-PetrelOP
tbh i'm trying to implement nextjs with my knowledge
i think i will use ur approach best, i will use username and password and save it in the local storage and check if the username and password is matching in every request
and send local storage in every request since after he login in once it's on his client only and use env file in the backend
Thank you for the help and the ideas!
also ur website is really clean and cool!
this approach will be problematic down the line 😅
i think your best bet is still a service like firebase/supabase
i think your best bet is still a service like firebase/supabase
@Ashy Storm-Petrel also ur website is really clean and cool!
thank youuu! 😄
@Dayo this approach will be problematic down the line 😅
i think your best bet is still a service like firebase/supabase
Ashy Storm-PetrelOP
it's not like i want more than 1 person to use the admin panel
that's why i want to use this approach
if i have websitte with login and stuff i'd use that but it's more of showcases and the person that want the website want to be able to upload posts
oh alright then. if you’re sure you don’t have sensitive info that can be compromised then it’s cool. this approach works
@Dayo oh alright then. if you’re sure you don’t have sensitive info that can be compromised then it’s cool. this approach works
Ashy Storm-PetrelOP
yah it's just showcasing their work and that's about it
alright cool
all the best!
Ashy Storm-PetrelOP
thank you again for your time!