🚩 add provision flow in oauth

Create a flow where if the user logs in with a registered Google account, they are immediately authenticated, but if no
account is found, create a new one.
This commit is contained in:
2025-08-11 22:54:31 +07:00
parent 7ce0e44389
commit 5d79ffd055
8 changed files with 94 additions and 17 deletions

View File

@ -0,0 +1,35 @@
import { UserHeaderInformation } from "../../../../helpers/http/userHeader/getUserHeaderInformation/types";
import { findUserService } from "../../../user/services/internal/findUser.service";
export const OAuthUserProvisionService = async (
payload: {
providerName: string;
openId: string;
email: string;
username?: string;
name: string;
avatar?: string;
bio?: string;
},
providerRawCallback: unknown,
userHeaderInfo: UserHeaderInformation
) => {
/**
* Create auth session if user already exist,
* create user account and give them auth session if not
*
* This is just example!!
*/
const providerId = `${payload.providerName}_${payload.openId}`;
const findUserResult = await findUserService({
identifier: providerId,
queryTarget: "providerId",
options: { verbosity: "exists" },
});
if (findUserResult) {
return "Already Created";
} else {
return "Not Found";
}
};