obtaining the accountId which the user linked

Hello, I'd like to add some functionality into my app which when a user links a new social account they will get redirected to /dashboard/feed/{newAccountId}. However, it doesn't seem possible that the account ID is able to be retrieved, I tried using the onSuccess callback, but the response data includes no information about the social that they just linked. Is there a work around for this?
onClick={async () => {
const response = await authClient.linkSocial({
provider: 'tiktok',
callbackURL: `/dashboard/feed/{accountId}`,
disableRedirect: true,
fetchOptions: {
onSuccess: (r) => {
console.log(r.data);
console.log(r.request);
console.log(r.response);
},
},
});
console.log(response);

window.open(response.data?.url, 'popup', 'width=500,height=600');
}}
onClick={async () => {
const response = await authClient.linkSocial({
provider: 'tiktok',
callbackURL: `/dashboard/feed/{accountId}`,
disableRedirect: true,
fetchOptions: {
onSuccess: (r) => {
console.log(r.data);
console.log(r.request);
console.log(r.response);
},
},
});
console.log(response);

window.open(response.data?.url, 'popup', 'width=500,height=600');
}}
6 Replies
v28
v28OP7d ago
doing some sort of accounts fetch, sorting by newest first wouldn't really solve the problem because id have to assume that the linkSocial flow was successful, is there a way to check for errors? is this even a nice way of doing it?
LightTab2
LightTab27d ago
You could try an after hook https://www.better-auth.com/docs/concepts/hooks Maybe the ctx will have the information and you can redirect users there
Hooks | Better Auth
Better Auth Hooks let you customize BetterAuth's behavior
LightTab2
LightTab27d ago
Oh wait, there is a callbackUrl, use this first
v28
v28OP7d ago
hi, thanks for the response. I am currrently using the callback url, but the issue is there is no way to obtain the new account information. I will take a look into the hooks though, thanks
LightTab2
LightTab27d ago
Yes, make your callback url "normal" then hook it, so maybe you can get the data this way, then redirect if you must This is what I meant
v28
v28OP14h ago
thank you for the reply lighttab, but unfortunately i was not able to figure this out, it doesnt look like the information is provided in the hook context.

Did you find this page helpful?