I need help with the Next auth Options.
I need inside a component a token which i need for hooks which currently should use
const response: AxiosResponse = await axios.get('https://localhost:8000/api/metadata', {
headers: {
Authorization: `Bearer ${token}`,
},
});
in the options i was not able to update the session user with a token..
export const options: NextAuthOptions = {
providers: [
GitHubProvider({
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
}),
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
let credentials_mapped = {
username: credentials?.username,
password: credentials?.password,
};
const res = await fetch('https://127.0.0.1:8000/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(credentials_mapped),
});
const user = await res.json();
if (res.ok && user) {
let token = user.token;
user.accessToken = token;
return user;
}
console.error('error', user);
return null;
}
}),
],
secret: process.env.SECRET,
callbacks: {
....
},
}