How can I store a jwt token into the server so I don't show it to the client?
Unanswered
Northern snakehead posted this in #help-forum
Northern snakeheadOP
// Form.tsx
"use client"
import { useForm } from '@mantine/form'
export default function Form(){
const form = useForm(formValidation)
<form onSubmit={form.onSubmit(authenticateUser)}>
{...My code}
</form>
}
// authenticate.ts
export default async function authenticateUser(values: IUserCredentials) {
try {
const res = await fetch("http://{domain_name}/api/user/PostLogin", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
Usuario: values.user,
Contrasena: values.password,
}),
})
const data = await res.json()
} catch (error) {
throw error
}
}
I am using the hook useForm from mantine, my question is, as i know the authenticateUser function is a client function because its parent component is a client component, how can I store the token that comes from data to the process.env.SESSION_TOKEN for example because I don't want to show the token in the cookies from client. Is there a way to do so?
"use client"
import { useForm } from '@mantine/form'
export default function Form(){
const form = useForm(formValidation)
<form onSubmit={form.onSubmit(authenticateUser)}>
{...My code}
</form>
}
// authenticate.ts
export default async function authenticateUser(values: IUserCredentials) {
try {
const res = await fetch("http://{domain_name}/api/user/PostLogin", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
Usuario: values.user,
Contrasena: values.password,
}),
})
const data = await res.json()
} catch (error) {
throw error
}
}
I am using the hook useForm from mantine, my question is, as i know the authenticateUser function is a client function because its parent component is a client component, how can I store the token that comes from data to the process.env.SESSION_TOKEN for example because I don't want to show the token in the cookies from client. Is there a way to do so?