omar
06/15/2022, 10:01 AMNeedle
06/15/2022, 10:01 AMomar
06/15/2022, 10:09 AMomar
06/15/2022, 10:09 AMomar
06/15/2022, 10:09 AMomar
06/15/2022, 10:19 AMomar
06/15/2022, 10:19 AMomar
06/15/2022, 10:19 AMjs
import { createContext, useState, useEffect, useContext } from 'react'
import { supabase } from '../utils/supabaseClient'
import { useRouter } from 'next/router'
import axios from 'axios'
const Context = createContext()
const Provider = ({ children }) => {
let [isLoading, setIsLoading] = useState(true)
let [session, setSession] = useState(null)
const [user, setUser] = useState(supabase.auth.user())
const router = useRouter()
useEffect(() => {
const getUserProfile = async () => {
const sessionUser = supabase.auth.user()
if(sessionUser) {
const {data: profile} = await supabase
.from('profile')
.select('*')
.eq('id', sessionUser.id)
.single()
setUser({
...sessionUser,
...profile,
})
setIsLoading(false)
}
}
getUserProfile()
supabase.auth.onAuthStateChange(() => {
getUserProfile()
})
}, [])
useEffect(() => {
axios.post('/api/set-supabase-cookie', {
event: user ? 'SIGNED_IN' : 'SIGNED_OUT',
session: supabase.auth.session(),
})
}, [user])
const login = async (email) => {
await supabase.auth.signIn({email})
}
const logout = async () => {
await supabase.auth.signOut()
setUser(null)
router.push('/')
}
const exposed = {
user,
login,
logout,
isLoading
}
return (
<Context.Provider value={exposed}>
{children}
</Context.Provider>
)
}
export const useUser = () => useContext(Context)
export default Provider
omar
06/15/2022, 10:20 AMomar
06/15/2022, 10:20 AMomar
06/15/2022, 10:23 AMjs
import { supabase } from '../../utils/supabaseClient'
import AuthTabs from './auth-tabs'
export default function Auth({}) {
async function handleOAuthLogin(email) {
let { error } = await supabase.auth.signIn({ email })
if (error) console.error('Error: ', error.message)
}
return (
<div>
<AuthTabs />
</div>
)
}
omar
06/15/2022, 10:24 AMjs
import { useState } from 'react'
import { supabase } from '../../utils/supabaseClient'
export default function SignIn({}) {
const [email, setEmail] = useState('')
const handleSignIn = async (email) => {
try {
const { error, user } = await supabase.auth.signIn({ email })
if (!error && !user) alert('Check your email for the login link!')
if (error) console.error('Error returned:', error.message)
} catch (error) {
console.error('Error thrown:', error.message)
alert(error.error_description || error)
}
}
return (
<div>
<div>
<div>
<label>Email</label>
<input
type="text"
name='email'
placeholder="Your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<a
onClick={(e) => {
e.preventDefault()
handleSignIn(email)
}}
href={'/channels'}
className="border border-navy bg-navy py-2 px-4 text-center font-bold text-snow"
>
Sign In
</a>
</div>
</div>
</div>
)
}
omar
06/15/2022, 10:28 AMjs
import { useState } from 'react'
import { supabase } from '../../utils/supabaseClient'
export default function SignUp({}) {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const handleSignUp = async (email, password) => {
try {
const { error, user } = await supabase.auth.signUp(
{
email,
password,
}
)
if (!error) alert('Check your email for the login link!')
if (error) {
console.error(
`Error Status: ${error.status}, Message: ${error.message}`
)
alert(`Error Message: ${error.message}`)
}
} catch (error) {
console.error('Error thrown:', error.message)
alert(error.error_description || error)
}
}
return (
<div>
<div>
<div>
<label>Email</label>
<input
type="text"
placeholder="Your email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<label>Password</label>
<input
type="password"
placeholder="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
</div>
<div>
<a
onClick={(e) => {
e.preventDefault()
handleSignUp(email, password)
}}
href={'/channels'}
className=""
>
Sign up
</a>
</div>
</div>
</div>
)
}
omar
06/15/2022, 10:29 AMomar
06/15/2022, 10:30 AMomar
06/15/2022, 12:38 PMgaryaustin
06/15/2022, 1:59 PMomar
06/15/2022, 2:11 PMgaryaustin
06/15/2022, 2:14 PMomar
06/15/2022, 3:23 PMomar
06/15/2022, 3:23 PMPOST https://provagxtnmrfxtldadcr.supabase.co/auth/v1/otp 500
omar
06/15/2022, 3:24 PMError returned: Database error saving new user
omar
06/15/2022, 3:27 PMgaryaustin
06/15/2022, 3:28 PMgaryaustin
06/15/2022, 3:29 PMgaryaustin
06/15/2022, 3:30 PMomar
06/15/2022, 3:32 PMgaryaustin
06/15/2022, 3:35 PMomar
06/15/2022, 3:36 PMgaryaustin
06/15/2022, 3:43 PMomar
06/15/2022, 3:44 PMEvent message
expected SASL response, got message type 0
Severity
FATAL
Postgres Username
postgres
Session ID
62a9fa43.eed2
Metadata
{
"file": "/var/log/postgresql/postgresql.csv",
"host": "db-provagxtnmrfxtldadcr",
"parsed": [
{
"application_name": null,
"backend_type": "client backend",
"command_tag": "authentication",
"connection_from": "185.7.214.104:47444",
"context": null,
"database_name": "bbbbbbb",
"detail": null,
"error_severity": "FATAL",
"hint": null,
"internal_query": null,
"internal_query_pos": null,
"leader_pid": null,
"location": null,
"process_id": 61138,
"query": null,
"query_id": 0,
"query_pos": null,
"session_id": "62a9fa43.eed2",
"session_line_num": 2,
"session_start_time": "2022-06-15 15:26:59 UTC",
"sql_state_code": "08P01",
"timestamp": "2022-06-15 15:26:59.246 UTC",
"transaction_id": 0,
"user_name": "postgres",
"virtual_transaction_id": "11/36748"
}
],
"parsed_from": null,
"project": "provagxtnmrfxtldadcr",
"source_type": "file"
}
omar
06/15/2022, 3:45 PMsecurity definer
omar
06/15/2022, 3:45 PMgaryaustin
06/15/2022, 3:45 PMomar
06/15/2022, 3:46 PMomar
06/15/2022, 3:46 PMgaryaustin
06/15/2022, 3:48 PMomar
06/15/2022, 3:48 PMomar
06/15/2022, 3:50 PMomar
06/15/2022, 3:51 PMomar
06/15/2022, 3:52 PMomar
06/15/2022, 3:52 PMFailed to load resource: the server responded with a status of 406 ()
garyaustin
06/15/2022, 3:54 PMgaryaustin
06/15/2022, 3:57 PMbegin
insert into public.users (uid, email)
values (new.id, new.email);
return new;
end;
It is security definer, return trigger. And email column is varchar.omar
06/15/2022, 3:58 PMgaryaustin
06/15/2022, 3:58 PMgaryaustin
06/15/2022, 3:59 PMomar
06/15/2022, 4:00 PMgaryaustin
06/15/2022, 4:00 PMomar
06/15/2022, 4:01 PMomar
06/15/2022, 4:02 PMomar
06/15/2022, 4:03 PMgaryaustin
06/15/2022, 4:04 PMomar
06/15/2022, 4:04 PMgaryaustin
06/15/2022, 4:05 PMgaryaustin
06/15/2022, 4:07 PMomar
06/15/2022, 4:09 PMomar
06/15/2022, 4:10 PMgaryaustin
06/15/2022, 4:10 PMomar
06/15/2022, 4:10 PMgaryaustin
06/15/2022, 4:15 PMomar
06/15/2022, 4:16 PMgaryaustin
06/15/2022, 4:17 PMomar
06/15/2022, 4:19 PMomar
06/15/2022, 4:20 PMomar
06/15/2022, 4:20 PMgaryaustin
06/15/2022, 4:22 PMomar
06/15/2022, 4:23 PMomar
06/15/2022, 4:23 PMgaryaustin
06/15/2022, 4:24 PMgaryaustin
06/15/2022, 4:26 PMomar
06/15/2022, 4:27 PMomar
06/15/2022, 4:27 PMomar
06/15/2022, 4:27 PMomar
06/15/2022, 4:28 PMomar
06/15/2022, 4:28 PMEvent message
current transaction is aborted, commands ignored until end of transaction block
Severity
ERROR
Postgres Username
supabase_auth_admin
Session ID
62a203b5.43dd
Metadata
{
"file": "/var/log/postgresql/postgresql.csv",
"host": "db-provagxtnmrfxtldadcr",
"parsed": [
{
"application_name": null,
"backend_type": "client backend",
"command_tag": "DEALLOCATE",
"connection_from": "10.109.104.183:37921",
"context": null,
"database_name": "postgres",
"detail": null,
"error_severity": "ERROR",
"hint": null,
"internal_query": null,
"internal_query_pos": null,
"leader_pid": null,
"location": null,
"process_id": 17373,
"query": "deallocate \"pgx_281\"",
"query_id": 0,
"query_pos": null,
"session_id": "62a203b5.43dd",
"session_line_num": 1902,
"session_start_time": "2022-06-09 14:29:09 UTC",
"sql_state_code": "25P02",
"timestamp": "2022-06-15 16:21:49.742 UTC",
"transaction_id": 1751,
"user_name": "supabase_auth_admin",
"virtual_transaction_id": "10/0"
}
],
"parsed_from": null,
"project": "provagxtnmrfxtldadcr",
"source_type": "file"
}
garyaustin
06/15/2022, 4:30 PMomar
06/15/2022, 4:31 PMomar
06/15/2022, 4:31 PMgaryaustin
06/15/2022, 4:32 PMomar
06/15/2022, 4:32 PMgaryaustin
06/15/2022, 4:33 PMgaryaustin
06/15/2022, 4:36 PMgaryaustin
06/15/2022, 4:42 PMomar
06/15/2022, 4:47 PMomar
06/15/2022, 4:47 PMomar
06/15/2022, 4:48 PMomar
06/15/2022, 4:48 PMgaryaustin
06/15/2022, 4:50 PMomar
06/15/2022, 6:09 PMomar
06/15/2022, 6:10 PMomar
06/15/2022, 6:11 PMomar
06/15/2022, 6:11 PMjs
import initStripe from 'stripe'
import {supabase} from '../../utils/supabaseClient'
const handler = async (req, res) => {
if(req.query.API_ROUTE_SECRET !== process.env.API_ROUTE_SECRET) {
return res.status(401).send("You're not authorized to call this API endpoint")
}
console.log(req.body)
const stripe = initStripe(process.env.STRIPE_SECRET_KEY)
const customer = await stripe.customers.create({
email: req.body.email
})
console.log({customer})
await supabase.from('profile').update({
stripe_customer: customer.id
}).eq('id', req.body.id)
res.send({ message: `stripe customer created: ${customer.id}`})
}
export default handler
garyaustin
06/15/2022, 6:13 PMomar
06/15/2022, 6:13 PMid
but then record
is undefined and i could only access without record req.body.email
and id
omar
06/15/2022, 6:13 PMomar
06/15/2022, 6:13 PMomar
06/15/2022, 6:14 PMomar
06/15/2022, 6:14 PMgaryaustin
06/15/2022, 6:16 PMomar
06/15/2022, 6:19 PMgaryaustin
06/15/2022, 6:30 PMomar
06/15/2022, 6:38 PMomar
06/15/2022, 6:40 PMgaryaustin
06/15/2022, 6:44 PMomar
06/15/2022, 7:36 PMomar
06/15/2022, 7:37 PMgaryaustin
06/15/2022, 7:42 PM