CLASSROOMIO-T-133: Send welcome email after onboarding

Co-authored-by: Rotimi Best <[email protected]>


Merge-request: CLASSROOMIO-MR-55
Merged-by: Best Admin <[email protected]>
This commit is contained in:
Rotimi Best
2023-08-26 11:58:57 +00:00
committed by Space Cloud
co-authored by Rotimi Best
parent b979da3db1
commit 7a5d341865
11 changed files with 352 additions and 45 deletions
+50
View File
@@ -0,0 +1,50 @@
import { render } from 'svelte-email';
import { json } from '@sveltejs/kit';
import WelcomeTemplate from './template.svelte';
import { getSendgrid, SENDGRID_FROM } from '$lib/utils/services/sendgrid';
import { getSupabase } from '$lib/utils/functions/supabase';
const sendgrid = getSendgrid();
const supabase = getSupabase();
export async function POST({ request }) {
const { to, name } = await request.json();
const accessToken = request.headers.get('Authorization');
console.log('/POST api/email/welcome', to, name);
if (!to || !name) {
return json({ success: false, message: 'Name and To are required fields' }, { status: 400 });
}
let user;
try {
const { data } = await supabase.auth.getUser(accessToken);
user = data.user;
} catch (error) {
console.error(error);
}
console.log('user', user);
if (!user) {
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
}
const options = {
from: SENDGRID_FROM,
to,
subject: 'Thank you so so so much for choosing ClassroomIO!',
html: render({
template: WelcomeTemplate,
props: {
name
}
})
};
sendgrid.send(options);
return json({
success: true,
message: 'Email sent'
});
}