Skip to content

Commit

Permalink
Merge pull request #1 from safeinsights/sk_shrimp_20
Browse files Browse the repository at this point in the history
SHRIMP-20
  • Loading branch information
chrisbendel authored Oct 3, 2024
2 parents 6334c57 + 4503544 commit 6a1c060
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HTTP_BASIC_AUTH=username:password
MANAGEMENT_APP_API_URL=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.idea
*.log
tmp/

.env
.next/
test-results/
*.tern-port
Expand Down
6 changes: 6 additions & 0 deletions environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly HTTP_BASIC_AUTH: string
readonly MANAGEMENT_APP_API_URL: string
}
}
3 changes: 2 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app-template",
"name": "trusted-output-app",
"version": "0.0.1",
"description": "App Template",
"description": "Trusted Output App",
"main": "index.js",
"scripts": {
"dev": "next dev",
Expand Down
4 changes: 2 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import '@mantine/core/styles.css'
import { Providers } from '@/components/providers'

export const metadata: Metadata = {
title: 'SafeInsights App Template',
description: 'An application',
title: 'SafeInsights - TOA',
description: 'SafeInsights - Trusted Output Application',
}

export default function RootLayout({
Expand Down
4 changes: 3 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { footerStyles, mainStyles, pageStyles } from './page.css'
export default function Home() {
return (
<div className={pageStyles}>
<main className={mainStyles}>Hello World</main>
<main className={mainStyles}>
<p>SafeInsights - Trusted Output App</p>
</main>
<footer className={footerStyles}>A SafeInsights production</footer>
</div>
)
Expand Down
39 changes: 39 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

const [AUTH_USER, AUTH_PASS] = (process.env.HTTP_BASIC_AUTH || ':').split(':')

function isAuthenticated(req: NextRequest) {
const authHeader = req.headers.get('authorization') || req.headers.get('Authorization')

if (!authHeader) {
return false
}

const auth = Buffer.from(authHeader.split(' ')[1], 'base64').toString().split(':')
const user = auth[0]
const pass = auth[1]

if (user == AUTH_USER && pass == AUTH_PASS) {
return true
} else {
return false
}
}

// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
if (!isAuthenticated(request)) {
return new NextResponse('Authentication required', {
status: 401,
headers: { 'WWW-Authenticate': 'Basic' },
})
}

return NextResponse.next()
}

// See "Matching Paths" below to learn more
export const config = {
matcher: '/((?!favicon.ico).*)',
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "vitest.config.mts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "vitest.config.mjs"],
"exclude": ["node_modules"]
}

0 comments on commit 6a1c060

Please sign in to comment.