Skip to content

Commit

Permalink
fix: remove username undefined to router
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-lemos committed Sep 13, 2021
1 parent 54774d6 commit f0ed075
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const login = async (credentials: Credentials) => {
return firebaseClient.auth().currentUser;
} catch (err) {
console.log('Login ERROR', err);
alert('Usuário ou senha incorreta.');
}
};

Expand All @@ -52,7 +51,6 @@ export const signup = async (credentials: Credentials) => {
});
} catch (err) {
console.log('SIGNUP ERROR', err);
alert('E-mail já cadastrado no sistema.');
}
};

Expand Down
12 changes: 8 additions & 4 deletions src/pages/[username].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface getScheduleInterface {
const getSchedule = async (data: getScheduleInterface) => {
const { when, username } = data;

if (!username) {
return null;
}

return axios({
method: 'get',
url: '/api/schedule',
Expand Down Expand Up @@ -61,13 +65,13 @@ const Schedule = () => {
})
.then(res => {
setLoading(false);
setData(res.data);
setData(res?.data);
})
.catch(() => router.push('/'));
.catch(err => console.log(err));

useEffect(() => {
refresh();
}, [when, router.query.username, router]);
}, [when, router.query.username]);

return (
<Container>
Expand Down Expand Up @@ -110,7 +114,7 @@ const Schedule = () => {
</Box>
)}
<SimpleGrid p={4} columns={2} spacing={4}>
{data.map(({ time, isBlocked }: any) => (
{data?.map(({ time, isBlocked }: any) => (
<TimeBlock
key={time}
time={time}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
import { firebaseServer } from '../../config/firebase/server';

const db = firebaseServer.firestore();

const profileDb = db.collection('profiles');
const agendaDb = db.collection('agenda');

Expand Down Expand Up @@ -74,7 +75,6 @@ const getSchedule = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(200).json(result);
} catch (err) {
console.log(`Error: ${err}`);
return res.status(401);
}
};

Expand Down

1 comment on commit f0ed075

@vercel
Copy link

@vercel vercel bot commented on f0ed075 Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.