-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add discussion redirect * Add missing license Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * add /discussion to login redirect path * update comment * fix e2e tests --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: David Crespo <[email protected]>
- Loading branch information
1 parent
c42214b
commit 615a076
Showing
3 changed files
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* Copyright Oxide Computer Company | ||
*/ | ||
|
||
import { redirect, type LoaderArgs } from '@remix-run/node' | ||
|
||
import { isAuthenticated } from '~/services/authn.server' | ||
import { fetchRfd } from '~/services/rfd.server' | ||
import { parseRfdNum } from '~/utils/parseRfdNum' | ||
|
||
import { resp404 } from './rfd.$slug' | ||
|
||
export async function loader({ request, params: { slug } }: LoaderArgs) { | ||
const num = parseRfdNum(slug) | ||
if (!num) throw resp404() | ||
|
||
const user = await isAuthenticated(request) | ||
const rfd = await fetchRfd(num, user) | ||
|
||
// !rfd covers both non-existent and private RFDs for the logged-out user. In | ||
// both cases, once they log in, if they have permission to read it, they'll | ||
// get the redirect, otherwise they will get 404. | ||
if (!rfd && !user) throw redirect(`/login?returnTo=/rfd/${num}/discussion`) | ||
|
||
// If you don't see an RFD but you are logged in, you can't tell whether you | ||
// don't have access or it doesn't exist. That's fine. | ||
if (!rfd || !rfd.discussion_link) throw resp404() | ||
|
||
return redirect(rfd.discussion_link) | ||
} |
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