52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
'use server';
|
|
|
|
import {auth} from "@/lib/better-auth/auth";
|
|
import {inngest} from "@/lib/inngest/client";
|
|
import {headers} from "next/headers";
|
|
|
|
export const signUpWithEmail = async ({ email, password, fullName, country, investmentGoals, riskTolerance, preferredIndustry }: SignUpFormData) => {
|
|
try {
|
|
const response = await auth.api.signUpEmail({ body: { email, password, name: fullName } })
|
|
|
|
if(response) {
|
|
try {
|
|
console.log('📤 Sending Inngest event: app/user.created for', email);
|
|
await inngest.send({
|
|
name: 'app/user.created',
|
|
data: { email, name: fullName, country, investmentGoals, riskTolerance, preferredIndustry }
|
|
});
|
|
console.log('✅ Inngest event sent successfully');
|
|
} catch (error) {
|
|
console.error('❌ Failed to send Inngest event:', error);
|
|
// Don't fail signup if email fails
|
|
}
|
|
}
|
|
|
|
return { success: true, data: response }
|
|
} catch (e) {
|
|
console.log('Sign up failed', e)
|
|
return { success: false, error: 'Sign up failed' }
|
|
}
|
|
}
|
|
|
|
export const signInWithEmail = async ({ email, password }: SignInFormData) => {
|
|
try {
|
|
const response = await auth.api.signInEmail({ body: { email, password } })
|
|
|
|
return { success: true, data: response }
|
|
} catch (e) {
|
|
console.log('Sign in failed', e)
|
|
return { success: false, error: 'Sign in failed' }
|
|
}
|
|
}
|
|
|
|
export const signOut = async () => {
|
|
try {
|
|
await auth.api.signOut({ headers: await headers() });
|
|
} catch (e) {
|
|
console.log('Sign out failed', e)
|
|
return { success: false, error: 'Sign out failed' }
|
|
}
|
|
}
|
|
|