Authentication with Credentials is working and setup, same for OAuth with Google.

This commit is contained in:
charles-gauthereau
2024-11-09 21:38:18 +01:00
parent 6541cfcc26
commit 6d90bb23c1
24 changed files with 784 additions and 341 deletions
+26
View File
@@ -0,0 +1,26 @@
"use server"
import {signIn, signOut} from "@/auth/auth";
import {redirect} from "next/navigation";
export const signOutAction = async () => {
await signOut({redirectTo: '/', redirect: true})
window.location.reload();
}
export const signInAction = async (type: string, formData?: any) => {
if (type === "google") {
await signIn(type, {redirectTo: '/dashboard'})
} else {
try {
await signIn(type, {
redirect: false,
password: formData.password,
email: formData.email
});
} catch (error) {
// const signInError = error as CredentialsSignin
console.error(error);
return {error: "Error loging in, please try again or check your credentials !"};
}
redirect("/")
}
}