You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createClient}from'@supabase/supabase-js'import{ethers}from'ethers'// ConfigurationconstSUPABASE_KEY=process.env.SUPABASE_CLIENT_API_KEYconstSUPABASE_URL=process.env.SUPABASE_URLconstsupabase=createClient(SUPABASE_URL,SUPABASE_KEY)exportconsthandler=asyncfunction(event: any,context: any){try{// Assuming the event.body contains the data we needconst{ message, signature, address }=JSON.parse(event.body)// Recover the address from the signatureconstrecoveredAddress=ethers.utils.verifyMessage(message,signature)// If the recovered address does not match the provided address, return an errorif(recoveredAddress!==address){thrownewError("Signature verification failed")}// Allowed columns to updateconstallowedColumns=['discord','telegram','twitter','matrix','push','email'];// If the message is empty, delete the user recordif(message==='{}'){let{ data, error }=awaitsupabase.from('users').delete().match({address: recoveredAddress})if(error)throwerrorreturn{statusCode: 200,body: JSON.stringify({message: "Record deleted successfully."})}}// Parse the signed messageconstparsedMessage=JSON.parse(message)// Prepare the record data based on the allowed columnsletrecordData: {[key: string]: any}={};for(constkeyinparsedMessage){if(allowedColumns.includes(key)){recordData[key]=parsedMessage[key];}}// Assuming you have a 'users' table with 'address' and allowedColumns fieldslet{ data, error }=awaitsupabase.from('user-settings').upsert(recordData).match({address: recoveredAddress})if(error)throwerrorreturn{statusCode: 200,body: JSON.stringify({message: "Record updated successfully."})}}catch(err){return{statusCode: 500,body: JSON.stringify({message: `Error: ${err.message}`})}}}
The text was updated successfully, but these errors were encountered:
jaybuidl
changed the title
Backend: integration with the email notification + contact setting service
Integration of the frontend with the email notification service.
Aug 1, 2023
Save the user's contact preference (email only for now).
Using this Netlify function with inputs
The text was updated successfully, but these errors were encountered: