add some hooks

This commit is contained in:
vergiLgood1 2025-02-19 00:05:16 +07:00
parent c7e0e2905c
commit 8137c58cd8
10 changed files with 132 additions and 66 deletions

3
sigap-website/.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"recommendations": ["denoland.vscode-deno"]
}

24
sigap-website/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"deno.enablePaths": [
"supabase/functions"
],
"deno.lint": true,
"deno.unstable": [
"bare-node-builtins",
"byonm",
"sloppy-imports",
"unsafe-proto",
"webgpu",
"broadcast-channel",
"worker-options",
"cron",
"kv",
"ffi",
"fs",
"http",
"net"
],
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}

View File

@ -0,0 +1,30 @@
import {
useParams,
usePathname,
useRouter,
useSearchParams,
} from "next/navigation";
import { useState } from "react";
export const useNavigations = () => {
const [loading, setLoading] = useState<boolean>(false);
const [open, setOpen] = useState<boolean>(false);
const [active, setActive] = useState<string>("");
const router = useRouter();
const params = useParams();
const searchParams = useSearchParams();
const pathname = usePathname();
return {
loading,
setLoading,
open,
setOpen,
active,
setActive,
router,
params,
searchParams,
pathname,
};
};

View File

@ -0,0 +1,74 @@
/**
* Custom hook to interact with Supabase client.
*
* @returns {Object} An object containing the Supabase client and session management functions.
*
* @function
* @name useSupabase
*
* @example
* const { supabase, getSession, refreshSession, setSession } = useSupabase();
*
* @property {Object} supabase - The Supabase client instance.
* @property {Function} getSession - Function to get the current session.
* @property {Function} refreshSession - Function to refresh the current session.
* @property {Function} setSession - Function to set a new session with access and refresh tokens.
*
* @typedef {Object} Session
* @property {string} access_token - The access token for the session.
* @property {string} refresh_token - The refresh token for the session.
*
* @throws {Error} Throws an error if there is an issue with getting or setting the session.
*/
//
import { createClient } from "@/utils/supabase/client";
export const useSupabase = () => {
const supabase = createClient();
const getSession = async () => {
const {
data: { session },
error,
} = await supabase.auth.getSession();
if (error) {
throw new Error(error.message);
}
const { access_token, refresh_token }: any = session;
await setSession(access_token, refresh_token);
return session;
};
const refreshSession = async () => {
const {
data: { session },
error,
} = await supabase.auth.refreshSession();
return session;
};
const setSession = async (access_token: string, refresh_token: string) => {
const { data, error } = await supabase.auth.setSession({
access_token,
refresh_token,
});
if (error) {
throw new Error(error.message);
}
return true;
};
return {
getSession,
refreshSession,
setSession,
};
};

View File

@ -1,22 +0,0 @@
# Update these with your Supabase details from your project settings > API
# https://app.supabase.com/project/_/settings/api
# Supabase Production URL
NEXT_PUBLIC_SUPABASE_URL="https://cppejroeyonsqxulinaj.supabase.co"
NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNwcGVqcm9leW9uc3F4dWxpbmFqIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzkzNjExMjYsImV4cCI6MjA1NDkzNzEyNn0.36XzD3ANlAmAYObYGxXkkydXLjN0VPv2rMNHnQcHoZU"
# Supabase Local URL
# NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
# NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
# Supabase Service Role Secret Key
SERVICE_ROLE_SECRET="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNwcGVqcm9leW9uc3F4dWxpbmFqIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTczOTM2MTEyNiwiZXhwIjoyMDU0OTM3MTI2fQ.iYIVeUChLIcC7NRaeJ6dViI9JiUZSMUKufFsDTfAkjA"
RESEND_API_KEY_TES="re_WtXdegYe_Ey3yiShKfZZtjCyY1agkEaSi"
SEND_EMAIL_HOOK_SECRET_TES="jeroAB/CXdS721OiHV0Ac0yRcxO7eNihgjblH62xMhLBNc6OwK3DQnkbrHjTlSw5anml2onNTolG3SzZ"
# db connection string
# Connect to Supabase via connection pooling with Supavisor.
DATABASE_URL="postgresql://prisma.cppejroeyonsqxulinaj:prisma@aws-0-ap-southeast-1.pooler.supabase.com:6543/postgres?pgbouncer=true"
# Direct connection to the database. Used for migrations.
DIRECT_URL="postgresql://prisma.cppejroeyonsqxulinaj:prisma@aws-0-ap-southeast-1.pooler.supabase.com:5432/postgres"

View File

@ -288,8 +288,3 @@ s3_region = "env(S3_REGION)"
s3_access_key = "env(S3_ACCESS_KEY)" s3_access_key = "env(S3_ACCESS_KEY)"
# Configures AWS_SECRET_ACCESS_KEY for S3 bucket # Configures AWS_SECRET_ACCESS_KEY for S3 bucket
s3_secret_key = "env(S3_SECRET_KEY)" s3_secret_key = "env(S3_SECRET_KEY)"
[auth.hook.send_email]
enabled = true
uri = "http://host.docker.internal:54321/functions/v1/send-email"
secrets = "v1,whsec_jeroAB/CXdS721OiHV0Ac0yRcxO7eNihgjblH62xMhLBNc6OwK3DQnkbrHjTlSw5anml2onNTolG3SzZ"

View File

@ -1,3 +0,0 @@
# Configuration for private npm package dependencies
# For more information on using private registries with Edge Functions, see:
# https://supabase.com/docs/guides/functions/import-maps#importing-from-private-registries

View File

@ -1,3 +0,0 @@
{
"imports": {}
}

View File

@ -1,32 +0,0 @@
// Follow this setup guide to integrate the Deno language server with your editor:
// https://deno.land/manual/getting_started/setup_your_environment
// This enables autocomplete, go to definition, etc.
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts"
console.log("Hello from Functions!")
Deno.serve(async (req) => {
const { name } = await req.json()
const data = {
message: `Hello ${name}!`,
}
return new Response(
JSON.stringify(data),
{ headers: { "Content-Type": "application/json" } },
)
})
/* To invoke locally:
1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start)
2. Make an HTTP request:
curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/resend' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'
*/

View File

@ -1,7 +1,7 @@
import { Webhook } from "https://esm.sh/standardwebhooks@1.0.0"; import { Webhook } from "https://esm.sh/standardwebhooks@1.0.0";
import { Resend } from "npm:resend"; import { Resend } from "npm:resend";
const resend = new Resend("re_WtXdegYe_Ey3yiShKfZZtjCyY1agkEaSi"); const resend = new Resend("re_4EyTgztQ_3istGdHQFeSTQsLBtH6oAdub" as string);
const hookSecret = const hookSecret =
"jeroAB/CXdS721OiHV0Ac0yRcxO7eNihgjblH62xMhLBNc6OwK3DQnkbrHjTlSw5anml2onNTolG3SzZ" as string; "jeroAB/CXdS721OiHV0Ac0yRcxO7eNihgjblH62xMhLBNc6OwK3DQnkbrHjTlSw5anml2onNTolG3SzZ" as string;