Skip to content

Commit

Permalink
Merge pull request #24 from odu-emse/ALMP-314
Browse files Browse the repository at this point in the history
Almp 314
  • Loading branch information
joeldesante authored Sep 26, 2022
2 parents 8c963ba + 2ac48b8 commit 1f68afb
Show file tree
Hide file tree
Showing 9 changed files with 11,624 additions and 17,462 deletions.
56 changes: 14 additions & 42 deletions components/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,20 @@ import { BiTask } from 'react-icons/bi';
import { BsStack } from 'react-icons/bs';
import Link from 'next/link';
import { RiShutDownLine } from 'react-icons/ri';
//import { checkForToken, decoder, loader } from './helpers'
import { GoPerson, GoSignIn } from 'react-icons/go';

import Image from 'next/image';
import {
MdLiveHelp,
MdOutlineExplore,
MdSpaceDashboard,
MdWidgets,
} from 'react-icons/md';
import { useEffect, useState } from 'react';
import { useState } from 'react';

export default function Sidebar() {
const [open, setOpen] = useState(false);
//const [loading, setLoading] = useState(false)
const [dropdown, setDropdown] = useState(false);
const [authenticated, setAuthenticated] = useState(true);

/*async function auth() {
try {
const res = await checkForToken()
res ? setAuthenticated(true) : setAuthenticated(false)
setLoading(false)
} catch (err) {
throw new Error(err)
}
}
useEffect(() => {
auth()
}, [])
if (loading) {
return loader()
}*/
const [authenticated] = useState(true);

return (
<aside
Expand Down Expand Up @@ -97,16 +77,10 @@ export default function Sidebar() {
loading="lazy"
/>
</div>

<div
className={`menu relative h-full flex flex-col justify-between`}
/*className={`menu relative h-full flex flex-col ${
authenticated ? 'justify-between' : 'justify-end'
}`}*/
>
<div className={`menu relative h-full flex flex-col justify-between`}>
{!authenticated === true ? (
<>
<Link href="/users/login">
<Link href="/login">
<a
className={`text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-4 text-sm font-medium uppercase tracking-widest ${
!open && 'flex items-center justify-center'
Expand Down Expand Up @@ -154,7 +128,7 @@ export default function Sidebar() {
)}
</a>
</Link>
<Link href="/program">
<Link href="/modules">
<a
className={`text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-4 text-sm font-medium uppercase tracking-widest ${
!open ? 'flex items-center justify-center' : ''
Expand Down Expand Up @@ -225,12 +199,13 @@ export default function Sidebar() {
{open ? (
'Account'
) : (
<img
className="md:h-8 md:w-8 h-auto w-auto rounded-full"
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt="user account avatar"
loading="lazy"
/>
<div className="w-10 h-10 overflow-hidden relative rounded-full">
<Image
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt="user account avatar"
layout="fill"
/>
</div>
)}
</button>
<div
Expand All @@ -243,10 +218,7 @@ export default function Sidebar() {
onMouseOut={() => setDropdown(!dropdown)}
onMouseLeave={() => setDropdown(!dropdown)}
>
<Link
//to={`/users/${decoder()}`}
href={`/users`}
>
<Link href={`/users/1`}>
<a
className="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
activeClassName="bg-gray-900 text-white px-3 py-4 text-sm font-medium border-l-4"
Expand Down
16 changes: 7 additions & 9 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
images: {
domains: [
"images.unsplash.com"
]
}
}
reactStrictMode: true,
swcMinify: true,
images: {
domains: ['images.unsplash.com', 'lh3.googleusercontent.com'],
},
};

module.exports = nextConfig
module.exports = nextConfig;
36 changes: 16 additions & 20 deletions pages/api/auth/check.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { OAuth2Client } from "google-auth-library";
import { OAuth2Client } from 'google-auth-library';

export default async function handler(req, res) {
const token = req.cookies?.auth;
if (token === undefined) {
res.status(401).send('Unauthorized');
return;
}

const token = req.cookies?.auth;
if (token === undefined) {
res.status(401).send("Unauthorized");
return;
}

const client = new OAuth2Client(process.env.GOOGLE_ID);
try {
await client.verifyIdToken({
idToken: token,
audience: process.env.GOOGLE_ID,
});
} catch(e) {
res.status(401).send("Unauthorized");
return;
}

res.status(200).send("OK");
const client = new OAuth2Client(process.env.GOOGLE_ID);
try {
const response = await client.verifyIdToken({
idToken: token,
audience: process.env.GOOGLE_ID,
});
res.status(200).json(response);
} catch (e) {
res.status(401).send('Unauthorized');
}
}

Loading

0 comments on commit 1f68afb

Please sign in to comment.