Use Google Image by default

This commit is contained in:
MartinBraquet
2025-07-29 11:33:52 +02:00
parent d579a9ec46
commit 38a92a2a90
5 changed files with 59 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
'use client';
import { useState, useRef, ChangeEvent } from 'react';
import { useState, useRef, ChangeEvent, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useSession } from 'next-auth/react';
import Image from 'next/image';
@@ -47,7 +47,8 @@ export default function CompleteProfile() {
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to upload image');
setError(errorData.error || 'Failed to upload image');
return;
}
const { url, key } = await response.json();
@@ -90,7 +91,8 @@ export default function CompleteProfile() {
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to update profile');
setError(errorData.error || 'Failed to update profile');
return
}
// Update the session to reflect the changes
@@ -106,6 +108,13 @@ export default function CompleteProfile() {
}
};
useEffect(() => {
const img = session?.user?.image;
if (img) {
setImage(img);
}
}, [session]);
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-md w-full space-y-8">

View File

@@ -2,27 +2,29 @@
import "./globals.css";
import Header from "./Header";
import Providers from "./providers";
import {Metadata} from "next";
export const metadata = {
export const metadata: Metadata = {
title: "BayesBond",
description: "A bonding platform for rational thinkers",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
export default function RootLayout(
{
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
<Providers>
<div className="min-h-screen flex flex-col">
<Header />
<main className="flex-1">{children}</main>
</div>
</Providers>
</body>
<body>
<Providers>
<div className="min-h-screen flex flex-col">
<Header/>
<main className="flex-1">{children}</main>
</div>
</Providers>
</body>
</html>
);
}

View File

@@ -28,16 +28,21 @@ export default function Post() {
}
const data = await response.json();
setProfile(data);
console.log(`Data image: ${data.image}`)
const img = data.image;
console.log(`Data image: ${img}`)
// If user has an image key, fetch the image
if (data.image) {
const imageResponse = await fetch(`/api/download?key=${data.image}`);
console.log(`imageResponse: ${imageResponse}`)
if (imageResponse.ok) {
const imageBlob = await imageResponse.json();
const imageUrl = imageBlob['url'];
setImage(imageUrl);
if (img) {
if (img.startsWith('http')) {
setImage(img);
} else {
const imageResponse = await fetch(`/api/download?key=${img}`);
console.log(`imageResponse: ${imageResponse}`)
if (imageResponse.ok) {
const imageBlob = await imageResponse.json();
const imageUrl = imageBlob['url'];
setImage(imageUrl);
}
}
}
} catch (error) {

View File

@@ -38,6 +38,11 @@ function RegisterComponent() {
};
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
function handleError(error: unknown) {
console.error("Registration error:", error);
setError(error instanceof Error ? error.message : "Registration failed");
}
try {
event.preventDefault();
setIsLoading(true);
@@ -50,7 +55,7 @@ function RegisterComponent() {
// Basic validation
if (!email || !password || !name) {
throw new Error("All fields are required");
handleError("All fields are required");
}
const res = await fetch("/api/auth/signup", {
@@ -61,7 +66,7 @@ function RegisterComponent() {
const data = await res.json();
if (!res.ok) {
throw new Error(data.error || "Registration failed");
handleError(data.error || "Registration failed");
}
// Show a success message with email verification notice
@@ -76,15 +81,14 @@ function RegisterComponent() {
});
if (response?.error) {
console.error("Sign-in error:", response.error);
throw new Error("Failed to sign in after registration");
handleError("Failed to sign in after registration");
}
redirect()
} catch (error) {
console.error("Registration error:", error);
setError(error instanceof Error ? error.message : "Registration failed");
handleError(error);
} finally {
setIsLoading(false);
}
}
@@ -140,8 +144,9 @@ function RegisterComponent() {
<div>
<div>
<h2 className="mt-6 text-center text-xl font-extrabold text-red-700">
The project is still in development, you can still sign up if you want to test it, but your account
may be deleted at any time. To get release updates, fill in this <a href='https://forms.gle/tKnXUMAbEreMK6FC6'>form</a>.
The project is still in development. You can sign up if you want to test it, but your account
may be deleted at any time. To get release updates, fill in this <a
href='https://forms.gle/tKnXUMAbEreMK6FC6'>form</a>.
</h2>
<h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
Create your account

View File

@@ -8,6 +8,11 @@ const nextConfig: NextConfig = {
hostname: 'bayesbond.s3.eu-north-1.amazonaws.com',
pathname: '/**', // allow all paths
},
{
protocol: 'https',
hostname: 'lh3.googleusercontent.com',
pathname: '/**', // allow all paths
},
],
},
};