-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from BookHive-ufcg/feat/login
Feat/login
- Loading branch information
Showing
11 changed files
with
345 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface CustomGlobalThis extends GlobalThis { | ||
isLoggedIn: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import NextAuth from 'next-auth'; | ||
import CredentialsProvider from 'next-auth/providers/credentials'; | ||
|
||
const url = process.env.BACK_END_URL || 'http://localhost:8080'; | ||
|
||
const handler = NextAuth({ | ||
providers: [ | ||
CredentialsProvider({ | ||
name: 'Credentials', | ||
credentials: { | ||
username: { label: 'Username', type: 'text', placeholder: 'username' }, | ||
password: { label: 'Password', type: 'password' }, | ||
}, | ||
async authorize(credentials) { | ||
// TODO: Admin user, remove this | ||
const admin = { id: "1", name: 'User', username: 'admin', password: 'admin' }; | ||
if (credentials?.username === admin.username && credentials?.password === admin.password) { | ||
return admin; | ||
} | ||
|
||
const response = await fetch(`${url}/user/${credentials?.username}`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
const user = await response.json(); | ||
|
||
if (credentials?.username === user.username && credentials?.password === user.password) { | ||
return user; | ||
} else { | ||
return null; | ||
} | ||
}, | ||
}), | ||
], | ||
pages: { | ||
signIn: '/login', | ||
}, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use client"; | ||
|
||
import React, { useEffect } from "react"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
const AuthProvider = ({ children }: { children: React.ReactNode }) => { | ||
const router = useRouter(); | ||
let isLoggedIn = false; | ||
|
||
if (typeof window !== "undefined") { | ||
isLoggedIn = window.localStorage["isLoggedIn"] === "true"; | ||
} | ||
|
||
useEffect(() => { | ||
const path = window.location.pathname; | ||
if (!isLoggedIn && path !== "/login" && path !== "/signup") { | ||
router.push("/login"); | ||
} | ||
}, [isLoggedIn, router]); | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export default AuthProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.button { | ||
width: 100%; | ||
height: 4rem; | ||
padding: 12px; | ||
font-size: 16px; | ||
border: none; | ||
|
Oops, something went wrong.
f557be2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for bookhive-web ready!
✅ Preview
https://bookhive-33mqt56ay-amiltoncabrals-projects.vercel.app
Built with commit f557be2.
This pull request is being automatically deployed with vercel-action