adding bunch of stuff for user getting
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user