👔 (oauth) add callback URI option for google

Adding a callback option to the Google OAuth provider used to define the OAuth callback URI. If not defined, the
callback URI will use the default value in the .env file.
This commit is contained in:
Rafi Arrafif
2025-08-14 23:43:16 +07:00
parent 3df1f342fc
commit 8abf3d3818
4 changed files with 11 additions and 8 deletions

View File

@ -38,4 +38,4 @@ GITHUB_DEFAULT_CALLBACK=
GOOGLE_CLIENT_ID= GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET= GOOGLE_CLIENT_SECRET=
GOOGLE_CLIENT_CALLBACK= GOOGLE_DEFAULT_CALLBACK=

View File

@ -3,9 +3,11 @@ import { mainErrorHandler } from "../../../helpers/error/handler";
import { googleRequestService } from "../services/http/googleRequest.service"; import { googleRequestService } from "../services/http/googleRequest.service";
import { returnReadResponse } from "../../../helpers/callback/httpResponse"; import { returnReadResponse } from "../../../helpers/callback/httpResponse";
export const googleRequestController = async (ctx: Context) => { export const googleRequestController = async (
ctx: Context & { query: { callback?: string } }
) => {
try { try {
const loginUrl = await googleRequestService(); const loginUrl = await googleRequestService(ctx.query.callback);
return returnReadResponse( return returnReadResponse(
ctx.set, ctx.set,
200, 200,

View File

@ -1,10 +1,11 @@
import { Google } from "arctic"; import { Google } from "arctic";
export const googleProvider = () => { export const googleProvider = (
const redirectURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_CLIENT_CALLBACK}`; callbackURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_DEFAULT_CALLBACK}`
) => {
return new Google( return new Google(
process.env.GOOGLE_CLIENT_ID!, process.env.GOOGLE_CLIENT_ID!,
process.env.GOOGLE_CLIENT_SECRET!, process.env.GOOGLE_CLIENT_SECRET!,
redirectURI callbackURI
); );
}; };

View File

@ -3,9 +3,9 @@ import { AppError } from "../../../../helpers/error/instances/app";
import { googleProvider } from "../../providers/google.provider"; import { googleProvider } from "../../providers/google.provider";
import { redis } from "../../../../utils/databases/redis/connection"; import { redis } from "../../../../utils/databases/redis/connection";
export const googleRequestService = async () => { export const googleRequestService = async (callbackURI?: string) => {
try { try {
const google = googleProvider(); const google = googleProvider(callbackURI);
const state = arctic.generateState(); const state = arctic.generateState();
const codeVerifier = arctic.generateCodeVerifier(); const codeVerifier = arctic.generateCodeVerifier();
const scopes = ["openid", "profile", "email"]; const scopes = ["openid", "profile", "email"];