👔 (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_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 { returnReadResponse } from "../../../helpers/callback/httpResponse";
export const googleRequestController = async (ctx: Context) => {
export const googleRequestController = async (
ctx: Context & { query: { callback?: string } }
) => {
try {
const loginUrl = await googleRequestService();
const loginUrl = await googleRequestService(ctx.query.callback);
return returnReadResponse(
ctx.set,
200,

View File

@ -1,10 +1,11 @@
import { Google } from "arctic";
export const googleProvider = () => {
const redirectURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_CLIENT_CALLBACK}`;
export const googleProvider = (
callbackURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_DEFAULT_CALLBACK}`
) => {
return new Google(
process.env.GOOGLE_CLIENT_ID!,
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 { redis } from "../../../../utils/databases/redis/connection";
export const googleRequestService = async () => {
export const googleRequestService = async (callbackURI?: string) => {
try {
const google = googleProvider();
const google = googleProvider(callbackURI);
const state = arctic.generateState();
const codeVerifier = arctic.generateCodeVerifier();
const scopes = ["openid", "profile", "email"];