Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHRIMP-20 #1

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}
Loading