Aland
Aland
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Aland on 6/13/2023 in #questions
Does NextAuth refresh access_token automatically?
As the title says I was wondering about refreshing the access token, Does NextAuth does that automatically? Or as the docs say, you have to implement it manually? https://authjs.dev/guides/basics/refresh-token-rotation#jwt-strategy
// https://accounts.google.com/.well-known/openid-configuration
// We need the `token_endpoint`.
const response = await fetch("https://oauth2.googleapis.com/token", {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
client_id: process.env.GOOGLE_ID,
client_secret: process.env.GOOGLE_SECRET,
grant_type: "refresh_token",
refresh_token: token.refresh_token,
}),
method: "POST",
})

const tokens: TokenSet = await response.json()

if (!response.ok) throw tokens

return {
...token, // Keep the previous token properties
access_token: tokens.access_token,
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
// Fall back to old refresh token, but note that
// many providers may only allow using a refresh token once.
refresh_token: tokens.refresh_token ?? token.refresh_token,
}
// https://accounts.google.com/.well-known/openid-configuration
// We need the `token_endpoint`.
const response = await fetch("https://oauth2.googleapis.com/token", {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
client_id: process.env.GOOGLE_ID,
client_secret: process.env.GOOGLE_SECRET,
grant_type: "refresh_token",
refresh_token: token.refresh_token,
}),
method: "POST",
})

const tokens: TokenSet = await response.json()

if (!response.ok) throw tokens

return {
...token, // Keep the previous token properties
access_token: tokens.access_token,
expires_at: Math.floor(Date.now() / 1000 + tokens.expires_in),
// Fall back to old refresh token, but note that
// many providers may only allow using a refresh token once.
refresh_token: tokens.refresh_token ?? token.refresh_token,
}
2 replies
TTCTheo's Typesafe Cult
Created by Aland on 2/13/2023 in #questions
new TRPCError "cause" field is not working
I have this error and lets say i want to provide more information and a custom error code in the cause field. But on the client the cause field is just not there i can't get the cause field.... , Am i doing anything wrong?
throw new TRPCError({
cause: { moreInfo: "moreInfo", code: 123 },
code: "FORBIDDEN",
message: "message",
});
throw new TRPCError({
cause: { moreInfo: "moreInfo", code: 123 },
code: "FORBIDDEN",
message: "message",
});
4 replies