OAuth skill issue

Ok thats 100% skill issue on my part.. but the flow that i know is:
Click "Sign In with Github" for example Redirect to Github OAuth login page Redirect back to my Url
when clicking on button which has:
authClient.signIn.social({ provider: 'github' })
authClient.signIn.social({ provider: 'github' })
all i get is my redirect request... anyone can point me to how i should be done? Thank you ❤️
8 Replies
bekacru
bekacru2mo ago
that is the correct behaviour not sure what you exactly need.
LoLesttK
LoLesttKOP2mo ago
the flow above thats not what happening.. all i get is a redirect with the signin/signup
bekacru
bekacru2mo ago
if it's returning the url but not actually redirectign make sure you haven't disabledFetchPlugins on your createAuthClient config. You can also just redirect to the url yourself using window.location.href. Alos if you're using next make sure you're not calling it on the server (using server actions).
LoLesttK
LoLesttKOP2mo ago
i don't have disabledFetchPlugins. And to be clear i get redirect to my endpoint /api/auth/sign-in/social when in practice i want it to go to github sign-in page and go back to my redirect url...
D3vision
D3vision2mo ago
Okay so if I understand you correctly what should be happening is: click button -> redirect to github oauth page -> redirect to redirect uri but what is currently happening is: click button -> redirect to redirect uri Is that correct? Also, for your convenience, these are all the options for the signIn.social function: - callbackURL (optional)
A URL to redirect the user to after signing in.
- newUserCallbackURL (optional)
A URL to redirect the user to if they are newly registered.
Useful when different routes are used for new and existing users.
- errorCallbackURL (optional)
A URL to redirect the user to if an error occurs.
If authentication is initiated from the client SDK, this defaults to the current URL.
- provider (required)
The OAuth2 provider to use.
- disableRedirect (optional)
A boolean flag to disable automatic redirection to the provider.
Useful if you want to handle redirection manually, such as in a popup or a different tab.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
D3vision
D3vision2mo ago
That could indeed also be the problem
LoLesttK
LoLesttKOP4w ago
Sorry for not responding i was out of town for a while. i managed to make it work like this.. altho im not sure its the best way but it works. ( Client side )
<button
onclick={async () => {

await authClient.signIn.social(
{ provider: "github" },
{
onSuccess: (r) => {
window.location.href = r.data; // r.data = res.url from server
},
},
);
}}>SignIn</button
<button
onclick={async () => {

await authClient.signIn.social(
{ provider: "github" },
{
onSuccess: (r) => {
window.location.href = r.data; // r.data = res.url from server
},
},
);
}}>SignIn</button
( Server side )
// API: /api/auth/sign-in/social
export async function POST(event: RequestEvent) {

const db = event.locals.db;
const auth = initAuth(db);

const res = await auth.api.signInSocial({
body: {
provider: "github",
callbackURL: "/callback/github",
},
});

return new Response(res.url as string);
}
// API: /api/auth/sign-in/social
export async function POST(event: RequestEvent) {

const db = event.locals.db;
const auth = initAuth(db);

const res = await auth.api.signInSocial({
body: {
provider: "github",
callbackURL: "/callback/github",
},
});

return new Response(res.url as string);
}
// callback api route
//API: /api/auth/callback/github
// callback api route
//API: /api/auth/callback/github

Did you find this page helpful?