mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-07 20:37:44 +00:00
fix: github provider should infer redirect_uri
This commit is contained in:
@@ -4,14 +4,11 @@ import { reactInvitationEmail } from "./email/invitation";
|
|||||||
import { LibsqlDialect } from "@libsql/kysely-libsql";
|
import { LibsqlDialect } from "@libsql/kysely-libsql";
|
||||||
import { reactResetPasswordEmail } from "./email/rest-password";
|
import { reactResetPasswordEmail } from "./email/rest-password";
|
||||||
import { resend } from "./email/resend";
|
import { resend } from "./email/resend";
|
||||||
|
import Database from "better-sqlite3";
|
||||||
const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev";
|
const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev";
|
||||||
const to = process.env.TEST_EMAIL || "";
|
const to = process.env.TEST_EMAIL || "";
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: new LibsqlDialect({
|
database: new Database("better-auth.db"),
|
||||||
url: process.env.TURSO_DATABASE_URL || "",
|
|
||||||
authToken: process.env.TURSO_AUTH_TOKEN || "",
|
|
||||||
}),
|
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
async sendResetPassword(url, user) {
|
async sendResetPassword(url, user) {
|
||||||
|
|||||||
@@ -45,8 +45,10 @@
|
|||||||
"@react-email/components": "^0.0.25",
|
"@react-email/components": "^0.0.25",
|
||||||
"@react-three/fiber": "^8.17.7",
|
"@react-three/fiber": "^8.17.7",
|
||||||
"@tanstack/react-query": "^5.56.2",
|
"@tanstack/react-query": "^5.56.2",
|
||||||
|
"@types/better-sqlite3": "^7.6.11",
|
||||||
"better-auth": "workspace:*",
|
"better-auth": "workspace:*",
|
||||||
"better-call": "0.2.3-beta.2",
|
"better-call": "0.2.3-beta.2",
|
||||||
|
"better-sqlite3": "^11.3.0",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "1.0.0",
|
"cmdk": "1.0.0",
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ export const callbackOAuth = createAuthEndpoint(
|
|||||||
...user,
|
...user,
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
console.log({ user, data });
|
|
||||||
const parsedState = parseState(c.query.state);
|
const parsedState = parseState(c.query.state);
|
||||||
if (!parsedState.success) {
|
if (!parsedState.success) {
|
||||||
c.context.logger.error("Unable to parse state");
|
c.context.logger.error("Unable to parse state");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { betterFetch } from "@better-fetch/fetch";
|
import { betterFetch } from "@better-fetch/fetch";
|
||||||
import { GitHub } from "arctic";
|
import { GitHub } from "arctic";
|
||||||
import type { OAuthProvider, ProviderOptions } from ".";
|
import type { OAuthProvider, ProviderOptions } from ".";
|
||||||
import { getRedirectURI } from "./utils";
|
import { getRedirectURI, validateAuthorizationCode } from "./utils";
|
||||||
|
|
||||||
export interface GithubProfile {
|
export interface GithubProfile {
|
||||||
login: string;
|
login: string;
|
||||||
@@ -53,26 +53,27 @@ export interface GithubProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GithubOptions extends ProviderOptions {}
|
export interface GithubOptions extends ProviderOptions {}
|
||||||
export const github = ({
|
export const github = (options: GithubOptions) => {
|
||||||
clientId,
|
|
||||||
clientSecret,
|
|
||||||
scope,
|
|
||||||
redirectURI,
|
|
||||||
}: GithubOptions) => {
|
|
||||||
const githubArctic = new GitHub(
|
const githubArctic = new GitHub(
|
||||||
clientId,
|
options.clientId,
|
||||||
clientSecret,
|
options.clientSecret,
|
||||||
getRedirectURI("github", redirectURI),
|
getRedirectURI("github", options.redirectURI),
|
||||||
);
|
);
|
||||||
|
const tokenEndpoint = "https://github.com/login/oauth/access_token";
|
||||||
return {
|
return {
|
||||||
id: "github",
|
id: "github",
|
||||||
name: "Github",
|
name: "Github",
|
||||||
createAuthorizationURL({ state, scopes }) {
|
createAuthorizationURL({ state, scopes }) {
|
||||||
const _scopes = scope || scopes || ["user:email"];
|
const _scopes = options.scope || scopes || ["user:email"];
|
||||||
return githubArctic.createAuthorizationURL(state, _scopes);
|
return githubArctic.createAuthorizationURL(state, _scopes);
|
||||||
},
|
},
|
||||||
validateAuthorizationCode: async (state) => {
|
validateAuthorizationCode: async (code, _, redirect) => {
|
||||||
return await githubArctic.validateAuthorizationCode(state);
|
return validateAuthorizationCode({
|
||||||
|
code,
|
||||||
|
redirectURI: options.redirectURI || getRedirectURI("google", redirect),
|
||||||
|
options,
|
||||||
|
tokenEndpoint,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async getUserInfo(token) {
|
async getUserInfo(token) {
|
||||||
const { data: profile, error } = await betterFetch<GithubProfile>(
|
const { data: profile, error } = await betterFetch<GithubProfile>(
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -149,12 +149,18 @@ importers:
|
|||||||
'@tanstack/react-query':
|
'@tanstack/react-query':
|
||||||
specifier: ^5.56.2
|
specifier: ^5.56.2
|
||||||
version: 5.56.2(react@19.0.0-rc-7771d3a7-20240827)
|
version: 5.56.2(react@19.0.0-rc-7771d3a7-20240827)
|
||||||
|
'@types/better-sqlite3':
|
||||||
|
specifier: ^7.6.11
|
||||||
|
version: 7.6.11
|
||||||
better-auth:
|
better-auth:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/better-auth
|
version: link:../../packages/better-auth
|
||||||
better-call:
|
better-call:
|
||||||
specifier: 0.2.3-beta.2
|
specifier: 0.2.3-beta.2
|
||||||
version: 0.2.3-beta.2
|
version: 0.2.3-beta.2
|
||||||
|
better-sqlite3:
|
||||||
|
specifier: ^11.3.0
|
||||||
|
version: 11.3.0
|
||||||
class-variance-authority:
|
class-variance-authority:
|
||||||
specifier: ^0.7.0
|
specifier: ^0.7.0
|
||||||
version: 0.7.0
|
version: 0.7.0
|
||||||
|
|||||||
Reference in New Issue
Block a user