Joshua
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
Do you have a buy me a coffee link?
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
Thank you so much
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
ok it sends back the refresh token
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
oh ok that makes sense, I've been logging in and out with this account for test purposes. I'll give it a go again
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
could it have something to do with my authClient on the frontend?
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
Yeah I've tried placing it in a different position in the google object put it's not working
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?

30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
tried this but the same was returned
my code:
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
enabled: true,
accessType: "offline",
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
scope: [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.googleapis.com/auth/calendar.events",
],
}
},
databaseHooks: {
account: {
create: {
after: async (account, ctx) => {
try {
console.log("account created: ", JSON.stringify(account, null, 2))
console.log("refresh token: ", account.refreshToken)
const user = await ctx?.context.internalAdapter.findUserById(account.userId)
if (!user) {
throw new Error("User not found")
}
await Agent.create({
userId: user.id,
name: user.name,
email: user.email,
refreshToken: account.refreshToken
})
} catch (error) { console.log(error) throw new Error("Failed to create agent") } } } } }, database: mongodbAdapter(db), plugins: [openAPI()], trustedOrigins: ["http://localhost:5173"], });
} catch (error) { console.log(error) throw new Error("Failed to create agent") } } } } }, database: mongodbAdapter(db), plugins: [openAPI()], trustedOrigins: ["http://localhost:5173"], });
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?

30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
ok so this with the account hook is how to do it?
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
@KiNFiSH @bekacru
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
I need to mention to that I'm not trying to refresh access tokens, I am trying to find the refreshTokens
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
I was printing out because I can't seem to find it
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
one more question, is it possible to use this in conjunction with the after hooks. An example of what I'm trying to do below:
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
socialProviders: {
google: {
enabled: true,
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
scope: [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.googleapis.com/auth/calendar.events",
],
refreshAccessToken: async (refreshToken) => {
console.log("refreshToken from google", JSON.stringify(refreshToken));
return {
refreshToken: refreshToken,
};
},
},
},
databaseHooks: {
user: {
create: {
after: async (user, refreshToken) => {
await Agent.create({
userId: user.id,
name: user.name,
email: user.email,
refreshToken: refreshToken,
});
},
},
},
},
database: mongodbAdapter(db),
trustedOrigins: ["http://localhost:5173"],
});
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
this is a great library btw. Moved from clerk and don't regret it
30 replies
BABetter Auth
•Created by Joshua on 4/12/2025 in #help
Is there a way to get the refresh token after using a social provider?
oh wow thank you I never even knew
30 replies