-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/sennetconsortium/portal-ui
- Loading branch information
Showing
15 changed files
with
123 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// middleware.ts | ||
import type {NextRequest} from 'next/server' | ||
import {NextResponse} from 'next/server' | ||
import {fetch_entity_type} from './lib/services.js' | ||
|
||
// Direct the user to the correct entity type view/edit page | ||
export async function middleware(request: NextRequest) { | ||
let uuid = request.nextUrl.searchParams.get("uuid") | ||
|
||
// Check for redirect cookie and if it exists just continue | ||
// Check if user is trying to create entity | ||
if (request.cookies.get('redirect')?.value === "true" || uuid === 'create') { | ||
const response = NextResponse.rewrite(request.url) | ||
response.cookies.delete("redirect") | ||
return response | ||
} | ||
|
||
let entity_type = await fetch_entity_type(uuid, request.cookies.get('groups_token')?.value); | ||
|
||
if (entity_type === "404") { | ||
return NextResponse.rewrite(new URL('/404', request.url)) | ||
} else if (entity_type != "") { | ||
let updated_url = request.url.replace(/(source|sample|dataset)/, entity_type) | ||
const response = NextResponse.redirect(updated_url) | ||
response.cookies.set("redirect", "true") | ||
return response | ||
} | ||
|
||
return NextResponse.rewrite(request.url) | ||
} | ||
|
||
// Match view and edit entity pages and grab the correct entity type | ||
export const config = { | ||
matcher: [ | ||
'/((?:source|sample|dataset).*)', | ||
'/edit/((?:source|sample|dataset).*)' | ||
], | ||
// Need to make exceptions for lodash | ||
// https://nextjs.org/docs/messages/edge-dynamic-code-evaluation | ||
unstable_allowDynamic: [ | ||
'/node_modules/lodash*/**', | ||
'/node_modules/babel-runtime/**' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters