hanako
Explore posts from serversCDCloudflare Developers
•Created by hanako on 9/1/2024 in #pages-help
turnstile - captcha verification process failed
/signin/+page.server.ts
import type { Actions, PageServerLoad } from "./$types";
import { fail, redirect } from "@sveltejs/kit";
export const load: PageServerLoad = async ({ locals }) => {
const session = await locals.getSession();
if (session) {
throw redirect(302, `/user/${session.user.user_metadata.username}`);
}
return {
session: null,
};
};
export const actions: Actions = {
default: async ({ request, locals }) => {
const formData = await request.formData();
const email = formData.get("email");
const password = formData.get("password");
if (typeof email !== "string" || typeof password !== "string") {
return fail(400, { error: "Invalid form data" });
}
const { data, error: signinError } =
await locals.supabase.auth.signInWithPassword({
email,
password,
});
if (signinError) {
console.error("Signin error:", signinError);
return fail(400, { error: signinError.message });
}
if (!data.user) {
return fail(400, { error: "No user returned after signin" });
}
// Fetch user data from the users table
const { data: userData, error: userError } = await locals.supabase
.from("users")
.select("username")
.eq("id", data.user.id)
.single();
if (userError) {
console.error("Error fetching user data:", userError);
return fail(500, {
error: "Error fetching user data. Please try again.",
});
}
throw redirect(302, `/user/${userData.username}`);
},
};
import type { Actions, PageServerLoad } from "./$types";
import { fail, redirect } from "@sveltejs/kit";
export const load: PageServerLoad = async ({ locals }) => {
const session = await locals.getSession();
if (session) {
throw redirect(302, `/user/${session.user.user_metadata.username}`);
}
return {
session: null,
};
};
export const actions: Actions = {
default: async ({ request, locals }) => {
const formData = await request.formData();
const email = formData.get("email");
const password = formData.get("password");
if (typeof email !== "string" || typeof password !== "string") {
return fail(400, { error: "Invalid form data" });
}
const { data, error: signinError } =
await locals.supabase.auth.signInWithPassword({
email,
password,
});
if (signinError) {
console.error("Signin error:", signinError);
return fail(400, { error: signinError.message });
}
if (!data.user) {
return fail(400, { error: "No user returned after signin" });
}
// Fetch user data from the users table
const { data: userData, error: userError } = await locals.supabase
.from("users")
.select("username")
.eq("id", data.user.id)
.single();
if (userError) {
console.error("Error fetching user data:", userError);
return fail(500, {
error: "Error fetching user data. Please try again.",
});
}
throw redirect(302, `/user/${userData.username}`);
},
};
3 replies
CDCloudflare Developers
•Created by hanako on 9/1/2024 in #pages-help
turnstile - captcha verification process failed
/signin/+page.svelte
<script lang="ts">
import type { SubmitFunction } from "@sveltejs/kit";
import { enhance } from "$app/forms";
import { Input } from "$lib/components/ui/input";
import { Button } from "$lib/components/ui/button";
import { LoaderCircle } from "lucide-svelte";
import { PUBLIC_TURNSTILE_SITE_KEY } from "$env/static/public";
let email = "";
let password = "";
let error: string = "";
let isLoading = false;
const handleEnhance: SubmitFunction = () => {
isLoading = true;
error = "";
return async ({ result, update }) => {
if (result.type === "failure") {
error = result.data?.error || "An unknown error occurred";
console.error("Sign-in failure:", result);
} else if (result.type === "redirect") {
return;
} else if (result.type === "success") {
console.log("Sign-in success:", result);
}
await update();
isLoading = false;
};
};
</script>
<svelte:head>
<title>Sign in</title>
<link rel="icon" href="/favicon.png" />
<script
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
async
defer
></script>
</svelte:head>
//...
<form method="POST" class="mt-8 space-y-6" use:enhance={handleEnhance}>
//input fields here
{#if error}
<p class="text-red-500">{error}</p>
{/if}
<div
class="cf-turnstile"
data-sitekey={PUBLIC_TURNSTILE_SITE_KEY}
data-callback="javascriptCallback"
></div>
<Button type="submit" class="w-full bg-teal-400" disabled={isLoading}>
{#if isLoading}
<LoaderCircle class="animate-spin mr-2 h-4 w-4" />
Signing in...
{:else}
Sign in
{/if}
</Button>
</form>
//...
<script lang="ts">
import type { SubmitFunction } from "@sveltejs/kit";
import { enhance } from "$app/forms";
import { Input } from "$lib/components/ui/input";
import { Button } from "$lib/components/ui/button";
import { LoaderCircle } from "lucide-svelte";
import { PUBLIC_TURNSTILE_SITE_KEY } from "$env/static/public";
let email = "";
let password = "";
let error: string = "";
let isLoading = false;
const handleEnhance: SubmitFunction = () => {
isLoading = true;
error = "";
return async ({ result, update }) => {
if (result.type === "failure") {
error = result.data?.error || "An unknown error occurred";
console.error("Sign-in failure:", result);
} else if (result.type === "redirect") {
return;
} else if (result.type === "success") {
console.log("Sign-in success:", result);
}
await update();
isLoading = false;
};
};
</script>
<svelte:head>
<title>Sign in</title>
<link rel="icon" href="/favicon.png" />
<script
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
async
defer
></script>
</svelte:head>
//...
<form method="POST" class="mt-8 space-y-6" use:enhance={handleEnhance}>
//input fields here
{#if error}
<p class="text-red-500">{error}</p>
{/if}
<div
class="cf-turnstile"
data-sitekey={PUBLIC_TURNSTILE_SITE_KEY}
data-callback="javascriptCallback"
></div>
<Button type="submit" class="w-full bg-teal-400" disabled={isLoading}>
{#if isLoading}
<LoaderCircle class="animate-spin mr-2 h-4 w-4" />
Signing in...
{:else}
Sign in
{/if}
</Button>
</form>
//...
3 replies
CDCloudflare Developers
•Created by hanako on 8/24/2024 in #pages-help
how do I configure DNS records for a pages domain
ohh...okay. thanks for the help
7 replies
CDCloudflare Developers
•Created by hanako on 8/24/2024 in #pages-help
how do I configure DNS records for a pages domain
the app is also built with supabase. Any way from there like SMTP settings? using the supabase url or something?
7 replies
CDCloudflare Developers
•Created by hanako on 8/24/2024 in #pages-help
how do I configure DNS records for a pages domain
ah...damn
7 replies
CDCloudflare Developers
•Created by hanako on 8/24/2024 in #pages-help
how do I configure DNS records for a pages domain
I could not find anything related on the dashboard. Or maybe I missed it
7 replies
DTDrizzle Team
•Created by hanako on 5/8/2024 in #help
cannot find module 'drizzle-orm/pg-core' on pnpm
package.json :
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@auth/drizzle-adapter": "^1.0.1",
"@next/env": "^14.2.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.30.10",
"lucide-react": "^0.378.0",
"next": "14.2.3",
"next-auth": "5.0.0-beta.17",
"pg": "^8.11.5",
"postgres": "^3.4.4",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/node": "^20",
"@types/pg": "^8.11.6",
"@types/react": "^18",
"@types/react-dom": "^18",
"drizzle-kit": "^0.20.18",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@auth/drizzle-adapter": "^1.0.1",
"@next/env": "^14.2.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.30.10",
"lucide-react": "^0.378.0",
"next": "14.2.3",
"next-auth": "5.0.0-beta.17",
"pg": "^8.11.5",
"postgres": "^3.4.4",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/node": "^20",
"@types/pg": "^8.11.6",
"@types/react": "^18",
"@types/react-dom": "^18",
"drizzle-kit": "^0.20.18",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
2 replies