Skip to content

Commit

Permalink
ENV config
Browse files Browse the repository at this point in the history
  • Loading branch information
roshanrajeev committed Apr 26, 2021
1 parent 7e44aa8 commit 6ac8054
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/Header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Header = () => {
if(localStorage.getItem('macebook-isauth')){
localStorage.removeItem('macebook-isauth')
}
const res = await fetch(`${process.env.API}/api/logout`, {
const res = await fetch(`${process.env.API}/logout`, {
method: 'GET',
credentials: 'include'
})
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
includePaths: [path.join(__dirname, 'styles')]
},
env: {
API: 'http://localhost:5001'
API: 'http://localhost:5001/api'
}
}
2 changes: 1 addition & 1 deletion pages/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Feeds = ({feeds}) => {
}

Feeds.getInitialProps = async (ctx) => {
const res = await fetch(`${process.env.API}/api/feeds`, {
const res = await fetch(`${process.env.API}/feeds`, {
method: 'GET',
credentials: 'include',
headers: ctx.req ? {cookie: ctx.req.headers.cookie} : undefined
Expand Down
4 changes: 2 additions & 2 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Home() {
return(
<Layout>
<SEO title="Macebook"/>
<div className={styles.heading}>MACE Alumini Portal</div>
<div className={styles.heading}>MACE Alumni Portal</div>
</Layout>
)
}
}
13 changes: 6 additions & 7 deletions pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ const Login = () => {
const handleClick = async (e) => {
e.preventDefault()
try {
const res = await fetch(`${process.env.API}/api/login`, {
const res = await fetch(`${process.env.API}/login`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username, password}),
credentials: 'include'
})
const user = await res.json()
if(res.status == 404){
return console.log("Invalid Username or Password")

if(res.status == 404 || res.status == 401){
return alert("Invalid Username or Password")
}

if(res.status == 200){
console.log("You're Logged In!")
localStorage.setItem('macebook-isauth', true)
// return router.push(`/user/${user.username}`)
return Router.replace('/feeds')
}
console.log("Failed to login!")
} catch (error) {
console.log("Failed to login!")
console.log("Server not responding!")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pages/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Messaging = ({messages}) => {
}

Messaging.getInitialProps = async (ctx) => {
const res = await fetch(`${process.env.API}/api/messages`, {
const res = await fetch(`${process.env.API}/messages`, {
method: 'GET',
credentials: 'include',
headers: ctx.req ? {cookie: ctx.req.headers.cookie} : undefined
Expand Down
2 changes: 1 addition & 1 deletion pages/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Notifications = ({notifications}) => {
}

Notifications.getInitialProps = async (ctx) => {
const res = await fetch(`${process.env.API}/api/notifications`, {
const res = await fetch(`${process.env.API}/notifications`, {
method: 'GET',
credentials: 'include',
headers: ctx.req ? {cookie: ctx.req.headers.cookie} : undefined
Expand Down
2 changes: 1 addition & 1 deletion pages/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Profile = () => {
}

Profile.getInitialProps = async (ctx) => {
const res = await fetch(`${process.env.API}/api/profile`, {
const res = await fetch(`${process.env.API}/profile`, {
method: 'GET',
credentials: 'include',
headers: ctx.req ? {cookie: ctx.req.headers.cookie} : undefined
Expand Down
2 changes: 1 addition & 1 deletion pages/user/[username].js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const UserProfile = (props) => {
export async function getServerSideProps(ctx){
const cookie = ctx.req.headers.cookie

const res = await fetch(`${process.env.API}/api/users/${ctx.params.username}`, {
const res = await fetch(`${process.env.API}/users/${ctx.params.username}`, {
headers: {
cookie
}
Expand Down

0 comments on commit 6ac8054

Please sign in to comment.