feat: verify users email (#215)
* worked on the email verification * worked on the email verification * fixed the emailing issue and the supabase updating issue * chore: add timer to resend, add supabase.server, enforce unique email * chore: remove nodemailer logger * remove async * remove disposable email verification --------- Co-authored-by: Rotimi Best <best@classroomio.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { PUBLIC_SUPABASE_URL } from '$env/static/public';
|
||||
import { PRIVATE_SUPABASE_SERVICE_ROLE } from '$env/static/private';
|
||||
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
export let supabase: SupabaseClient;
|
||||
|
||||
/**
|
||||
* Should only be called on server files
|
||||
*
|
||||
* @returns supabase
|
||||
*/
|
||||
export const getServerSupabase = () => {
|
||||
if (supabase) return supabase;
|
||||
|
||||
supabase = createClient(PUBLIC_SUPABASE_URL, PRIVATE_SUPABASE_SERVICE_ROLE, {
|
||||
auth: {
|
||||
persistSession: false,
|
||||
autoRefreshToken: false,
|
||||
detectSessionInUrl: false
|
||||
}
|
||||
});
|
||||
|
||||
return supabase;
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { supabase } from '$lib/utils/functions/supabase';
|
||||
|
||||
export const NOTIFICATION_NAME = {
|
||||
WELCOME_TO_APP: 'WELCOME TO APP',
|
||||
VERIFY_EMAIL: 'VERFIY_EMAIL',
|
||||
INVITE_TEACHER: 'INVITE TEACHER',
|
||||
WELCOME_TEACHER_TO_COURSE: 'WELCOME TEACHER TO COURSE',
|
||||
SEND_TEACHER_STUDENT_BUY_REQUEST: 'SEND TEACHER STUDENT BUY REQUEST',
|
||||
@@ -15,6 +16,7 @@ export const NOTIFICATION_NAME = {
|
||||
|
||||
const NAME_TO_PATH = {
|
||||
[NOTIFICATION_NAME.WELCOME_TO_APP]: '/api/email/welcome',
|
||||
[NOTIFICATION_NAME.VERIFY_EMAIL]: '/api/email/verify_email',
|
||||
[NOTIFICATION_NAME.INVITE_TEACHER]: '/api/email/invite',
|
||||
[NOTIFICATION_NAME.WELCOME_TEACHER_TO_COURSE]: '/api/email/course/teacher_welcome',
|
||||
[NOTIFICATION_NAME.SEND_TEACHER_STUDENT_BUY_REQUEST]:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import {
|
||||
SMTP_HOST,
|
||||
SMTP_PORT,
|
||||
SMTP_USER,
|
||||
SMTP_PASSWORD,
|
||||
SMTP_USER_NOTIFY,
|
||||
@@ -24,7 +25,7 @@ export const getTransporter = async (
|
||||
|
||||
transporter = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: 465,
|
||||
port: parseInt(SMTP_PORT),
|
||||
secure: true,
|
||||
auth: {
|
||||
user: isPersonal ? SMTP_USER : SMTP_USER_NOTIFY,
|
||||
|
||||
@@ -21,6 +21,8 @@ interface ProfileStore {
|
||||
goal: string;
|
||||
source: string;
|
||||
telegram_chat_id: number | null;
|
||||
is_email_verified: boolean;
|
||||
verified_at: string;
|
||||
}
|
||||
|
||||
export const defaultUserState: UserStore = {
|
||||
@@ -41,7 +43,9 @@ export const defaultProfileState: ProfileStore = {
|
||||
role: '',
|
||||
goal: '',
|
||||
source: '',
|
||||
telegram_chat_id: null
|
||||
telegram_chat_id: null,
|
||||
is_email_verified: false,
|
||||
verified_at: ''
|
||||
};
|
||||
|
||||
export const user = writable<UserStore>(defaultUserState);
|
||||
|
||||
Reference in New Issue
Block a user