Skip to content

Commit

Permalink
Authentication implementation (#108)
Browse files Browse the repository at this point in the history
* feat: basic nextauth integration

* feat: login, logout and session implemented in nextauth

* feat(security) stubbed out singup feature. still needs input box validation

* fix: removed not-yet-implemented security features - only login is implemented

* fix(lint): allowing any type

* ui: change iconButton to Button and adjust placements for popovers

* ui: add show/hide adornments and add a maxWidth

---------

Co-authored-by: Matthew Stankiewicz <[email protected]>
  • Loading branch information
Plow74 and mattystank committed Aug 12, 2024
1 parent 7e45900 commit e8e326d
Show file tree
Hide file tree
Showing 17 changed files with 408 additions and 60 deletions.
14 changes: 14 additions & 0 deletions next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'next-auth/jwt'

declare module 'next-auth' {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
user: {
/** The user's postal address. */
address: string
} & DefaultSession['user']
jsessionid: string
}
}
140 changes: 136 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"cypress:open:dev": "cypress open --config-file cypress/config/cypress.config.dev.ts",
"test": "npm run cypress:open:dev",
"cypress:run:dev": "cypress run --config-file cypress/config/cypress.config.dev.ts",
"test:dev": "npm run cypress:run:dev"
"test:dev": "npm run cypress:run:dev",
"type-check": "tsc --noEmit"
},
"dependencies": {
"@emotion/cache": "^11.11.0",
Expand All @@ -24,6 +25,8 @@
"lodash": "^4.17.21",
"marked": "^12.0.2",
"next": "14.2.3",
"next-auth": "^4.24.7",
"nookies": "^2.5.2",
"react": "^18",
"react-countup": "^6.5.3",
"react-dom": "^18",
Expand Down
6 changes: 6 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import NextAuth from 'next-auth'
import { authOptions } from '@/lib/auth'

const handler = NextAuth(authOptions)

export { handler as GET, handler as POST }
36 changes: 21 additions & 15 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter'
import type { Metadata } from 'next'
import React from 'react'
import Script from 'next/script'
import SessionProvider from '@/components/SessionProvider'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'

export const metadata: Metadata = {
title: 'SITE UI 4.0',
Expand All @@ -32,7 +35,8 @@ const footer = {
marginTop: 'auto',
}

export default function RootLayout({ children }: { children: React.ReactNode }) {
export default async function RootLayout({ children }: { children: React.ReactNode }) {
const session = await getServerSession(authOptions)
return (
<html lang="en">
<head>
Expand All @@ -51,22 +55,24 @@ export default function RootLayout({ children }: { children: React.ReactNode })
/>
</head>
<body>
<ThemeProvider theme={lightTheme}>
<CssBaseline>
<AppRouterCacheProvider>
<Box sx={content}>
<CombinedNavAndAppBar />
<Box role="main" sx={pageContainer}>
{children}
<Box sx={footer}>
<Ankle />
<Footer />
<SessionProvider session={session}>
<ThemeProvider theme={lightTheme}>
<CssBaseline>
<AppRouterCacheProvider>
<Box sx={content}>
<CombinedNavAndAppBar />
<Box role="main" sx={pageContainer}>
{children}
<Box sx={footer}>
<Ankle />
<Footer />
</Box>
</Box>
</Box>
</Box>
</AppRouterCacheProvider>
</CssBaseline>
</ThemeProvider>
</AppRouterCacheProvider>
</CssBaseline>
</ThemeProvider>
</SessionProvider>
</body>
</html>
)
Expand Down
3 changes: 3 additions & 0 deletions src/components/SessionProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client'
import { SessionProvider } from 'next-auth/react'
export default SessionProvider
7 changes: 3 additions & 4 deletions src/components/shared/nav/CombinedNavAndAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import SiteAppBar from '@/components/shared/nav/app-bar/SiteAppBar'
import Nav from '@/components/shared/nav/nav/Nav'

export default function CombinedNavAndAppBar() {
const [auth, setAuth] = React.useState(false)
const handleAuthChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setAuth(event.target.checked)
//setAuth(event.target.checked)
}

// TODO: default to false based on DEV_MODE env var
Expand All @@ -25,8 +24,8 @@ export default function CombinedNavAndAppBar() {
return (
<Box sx={{ display: 'flex' }}>
<CssBaseline />
<SiteAppBar open={open} handleDrawerOpen={handleDrawerOpen} auth={auth} />
<Nav open={open} handleDrawerClose={handleDrawerClose} auth={auth} handleAuthChange={handleAuthChange} />
<SiteAppBar open={open} handleDrawerOpen={handleDrawerOpen} />
<Nav open={open} handleDrawerClose={handleDrawerClose} handleAuthChange={handleAuthChange} />
</Box>
)
}
Loading

0 comments on commit e8e326d

Please sign in to comment.