Skip to content

Commit

Permalink
Merge pull request #188 from wizelineacademy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JoseCSG authored Jun 3, 2024
2 parents ca0e1ef + 38499b9 commit 6bd68ce
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 0 additions & 2 deletions actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { signIn } from "@/auth";
import { registerUser } from "./services/user";
import { DatabaseErrorType } from "./types/errorTypes";
import { DatabaseError } from "pg";
import { redirect } from "next/navigation";

export const loginAction = async (formData: FormData) => {
try {
await signIn("credentials", formData);
redirect("/profile");
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
Expand Down
4 changes: 4 additions & 0 deletions app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import { loginAction } from "@/actions";
import FormTextInput from "@/components/FormTextInput";
import Link from "next/link";
import { useRouter } from "next/navigation";
import toast from "react-hot-toast";

const Login = () => {
const router = useRouter();
const clientLoginAction = async (formData: FormData) => {
const result = await loginAction(formData);
if (result) {
Expand All @@ -16,6 +18,8 @@ const Login = () => {
toast.error("Something went wrong. Try again.");
break;
}
} else {
router.push("/dashboard");
}
};

Expand Down
5 changes: 4 additions & 1 deletion auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const authConfig = {
return Response.redirect(new URL("/forbbiden", nextUrl));
}
}

console.log("url actual", nextUrl.pathname);
if (
nextUrl.pathname.startsWith("/login") ||
nextUrl.pathname.startsWith("/register")
Expand All @@ -76,6 +76,9 @@ export const authConfig = {

return true;
},
async redirect({ url, baseUrl }) {
return url.startsWith(baseUrl) ? url : baseUrl;
},
async jwt({ token, user: jwtUser, trigger }) {
// Persist the OAuth access_token and or the user id to the token right after signin
if (trigger === "signIn") {
Expand Down

0 comments on commit 6bd68ce

Please sign in to comment.