allow only registered publishers to set up local credentials; fix menu; fix signin UI

This commit is contained in:
Dobromir Popov
2024-04-30 13:15:37 +03:00
parent 8f7446d214
commit ad42fbf639
3 changed files with 38 additions and 20 deletions

View File

@ -217,6 +217,16 @@ function FooterSection() {
return (
footerMenu.map((item, index) => (
item.roles ? (
<ProtectedRoute key={index} allowedRoles={item.roles} deniedMessage="">
<div
className="px-4 py-1 mt-2 cursor-pointer hover:underline hover:text-blue-600 dark:hover:text-blue-400"
onClick={() => navigateTo(item.url)}
>
<span className="text-gray-700 dark:text-gray-300 font-medium">{item.text}</span>
</div>
</ProtectedRoute>
) : (
<div
key={index}
className="px-4 py-1 mt-2 cursor-pointer hover:underline hover:text-blue-600 dark:hover:text-blue-400"
@ -224,6 +234,7 @@ function FooterSection() {
>
<span className="text-gray-700 dark:text-gray-300 font-medium">{item.text}</span>
</div>
)
))
);
}

View File

@ -108,18 +108,24 @@ export const authOptions: NextAuthOptions = {
}
}
else {
const pub = await prisma.publisher.findUnique({ where: { email: credentials.username } });
if (pub) {
const passHash = await bcrypt.hash(credentials.password, 10);
const newUser = await prisma.user.create({
data: {
name: credentials.username,
email: credentials.username,
passwordHashLocalAccount: passHash
}
});
console.log("New local credential user created for publisher ", pub.firstName, " ", pub.lastName, " (", pub.email, ")");
return newUser;
}
else {
throw new Error("Не можем да намерим твоя имейл '" + credentials?.username + "' в участниците в ССОМ. Моля свържи се с нас за да те регистрираме ако искаш да ползваш този имейл.");
// console.log("Creating new user in the database...");
// const passHash = await bcrypt.hash(credentials.password, 10);
// const newUser = await prisma.user.create({
// data: {
// name: credentials.username,
// email: credentials.username,
// passwordHashLocalAccount: passHash
// }
// });
// console.log("New user created in the database.");
// return newUser;
}
}
}
}

View File

@ -47,13 +47,14 @@ export default function SignIn({ csrfToken }) {
<div className="signin">
<div className="min-h-screen flex flex-col items-center justify-center">
{/* SSO Providers */}
<div className="space-y-4 w-full px-4">
<div className="mt-8 w-full max-w-xs px-4">
<button onClick={() => signIn('google', { callbackUrl: '/' })}
className="flex items-center justify-center w-full py-2 px-4 border border-gray-300 rounded shadow-sm text-sm text-gray-700 bg-white hover:bg-gray-50">
<img loading="lazy" height="24" width="24" alt="Google logo"
src="https://authjs.dev/img/providers/google.svg" className="mr-2" />
Влез чрез Google
</button>
{/* Add more buttons for other SSO providers here in similar style */}
</div>