adding bunch of stuff for user getting

This commit is contained in:
Arjun Patel
2022-01-13 22:33:05 -08:00
parent 9f5b3d072a
commit 4e4bc2bcc9
11 changed files with 2202 additions and 51 deletions
+34
View File
@@ -0,0 +1,34 @@
import { credential } from 'firebase-admin';
import { initializeApp } from 'firebase-admin/app';
import { NextApiRequest, NextApiResponse } from 'next';
import serviceAccount from '../../../nirvana-for-business-firebase-adminsdk.json'
initializeApp({
credential: credential.cert({
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
projectId: serviceAccount.project_id,
})
});
export default validateToken = async (req: NextApiRequest, res: NextApiResponse) => {
console.log('Validating token...');
try {
const { token } = JSON.parse(req.headers.authorization || '{}');
if (!token) {
return res.status(403).send({
errorCode: 403,
message: 'Auth token missing.'
});
}
const result = await validate(token);
return res.status(200).send(result);
} catch (err) {
return res.status(err.code).send({
errorCode: err.code,
message: err.message,
});
}
}
-30
View File
@@ -1,30 +0,0 @@
import { useAuth } from "../../contexts/authContext"
import { useRouter } from "next/router"
import { useEffect } from "react"
/**
* figure out where to take the user based on everything
*/
function RouteHandler() {
const { currUser, logOut } = useAuth()
const router = useRouter()
useEffect(() => {
// if not authenticated, take user to the login
if (!currUser) {
console.log('not authenticated...routing from dashboard to teams home')
router.push('/teams/login')
}
}, [currUser])
return (
<div className="text-white">this is the route handler page</div>
)
}
export async function getServerSideProps() {
// Pass data to the page via props
return { props: { } }
}
export default RouteHandler
+51
View File
@@ -0,0 +1,51 @@
import { useAuth } from "../../contexts/authContext"
import { useRouter } from "next/router"
import { useEffect } from "react"
import UserService from '../../services/userService'
import { User } from "../../models/user"
import { GetServerSidePropsContext } from "next"
/**
* figure out where to take the user based on everything
*/
function RouteHandler({ user }) {
const { currUser, logOut } = useAuth()
const router = useRouter()
useEffect(() => {
// if not authenticated, take user to the login
if (!currUser) {
console.log('not authenticated...routing from dashboard to teams home')
router.push('/teams/login')
}
// if user has no profile, then go to create profile
}, [currUser])
return (
<div className="text-black">this is the route handler page</div>
)
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
// get user data
const userService: UserService = new UserService()
var user: User | null = null
try {
user = await userService.getUser("asdf")
} catch(error) {
console.log(error)
}
// Pass data to the page via props
return { props: {
user
}
}
}
export default RouteHandler
View File