add users to loops post google sign in (#194)
This commit is contained in:
parent
701ace3dff
commit
f926a0f78c
@ -56,22 +56,7 @@ function createAuth() {
|
||||
});
|
||||
},
|
||||
afterEmailVerification: async (user) => {
|
||||
try {
|
||||
await upsertHostedVerifiedContact({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Failed to sync Loops profile after verification:",
|
||||
{
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
error,
|
||||
},
|
||||
);
|
||||
}
|
||||
await syncHostedVerifiedContact(user, "email verification");
|
||||
},
|
||||
},
|
||||
socialProviders: getSocialProviders(),
|
||||
@ -81,6 +66,17 @@ function createAuth() {
|
||||
}),
|
||||
plugins: [...baseAuthConfig.plugins, tanstackStartCookies()],
|
||||
databaseHooks: {
|
||||
user: {
|
||||
create: {
|
||||
after: async (user, context) => {
|
||||
if (context?.path !== "/callback/google") {
|
||||
return;
|
||||
}
|
||||
|
||||
await syncHostedVerifiedContact(user, "Google sign up");
|
||||
},
|
||||
},
|
||||
},
|
||||
session: {
|
||||
create: {
|
||||
before: async (session) => {
|
||||
@ -108,6 +104,25 @@ function createAuth() {
|
||||
|
||||
let authInstance: ReturnType<typeof createAuth> | null = null;
|
||||
|
||||
async function syncHostedVerifiedContact(
|
||||
user: { id: string; email: string; name?: string | null },
|
||||
context: string,
|
||||
) {
|
||||
try {
|
||||
await upsertHostedVerifiedContact({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Failed to sync Loops profile after ${context}:`, {
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getTrustedOrigins(baseUrl: string) {
|
||||
const trustedOrigins = [baseUrl];
|
||||
|
||||
@ -148,21 +163,29 @@ function getHostedSecret() {
|
||||
}
|
||||
|
||||
function getSocialProviders() {
|
||||
return {
|
||||
google: getGoogleSocialProviderConfig(),
|
||||
};
|
||||
}
|
||||
|
||||
function getGoogleSocialProviderConfig() {
|
||||
const googleClientId = env.GOOGLE_CLIENT_ID?.trim();
|
||||
const googleClientSecret = env.GOOGLE_CLIENT_SECRET?.trim();
|
||||
|
||||
if (!googleClientId || !googleClientSecret) {
|
||||
return undefined;
|
||||
if (!googleClientId) {
|
||||
throw new Error("GOOGLE_CLIENT_ID is required in hosted mode");
|
||||
}
|
||||
|
||||
if (!googleClientSecret) {
|
||||
throw new Error("GOOGLE_CLIENT_SECRET is required in hosted mode");
|
||||
}
|
||||
|
||||
return {
|
||||
google: {
|
||||
clientId: googleClientId,
|
||||
clientSecret: googleClientSecret,
|
||||
mapProfileToUser: (profile: { name?: string }) => ({
|
||||
name: profile.name,
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -183,6 +206,7 @@ export function hasHostedAuthConfig() {
|
||||
try {
|
||||
getHostedBaseUrl();
|
||||
getHostedSecret();
|
||||
getGoogleSocialProviderConfig();
|
||||
return (
|
||||
Reflect.get(env, "BYPASS_EMAIL_VERIFICATION") === "true" ||
|
||||
hasHostedAuthEmailConfig()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user