Commit 9362a78 1 parent 8d91c93 commit 9362a78 Copy full SHA for 9362a78
File tree 8 files changed +95
-55
lines changed
8 files changed +95
-55
lines changed Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+ import Skeleton from "@/components/Skeleton" ;
3
+ import { userManager } from "@/lib/auth" ;
4
+ import { useEffect } from "react" ;
5
+ import { AuthProvider , AuthProviderProps , useAuth } from "react-oidc-context" ;
6
+ import { permanentRedirect } from "next/navigation" ;
7
+
8
+ const config = {
9
+ userManager,
10
+ onSigninCallback : ( user ) => {
11
+ console . log ( user ) ;
12
+ permanentRedirect ( "/review" ) ;
13
+ } ,
14
+ } satisfies AuthProviderProps ;
15
+
16
+ export default function AuthLayout ( {
17
+ children,
18
+ } : Readonly < {
19
+ children : React . ReactNode ;
20
+ } > ) {
21
+ return < AuthProvider { ...config } > { children } </ AuthProvider > ;
22
+ }
Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+ import Skeleton from "@/components/Skeleton" ;
3
+ import { cn } from "@/lib/utils" ;
4
+ import { useEffect } from "react" ;
5
+ import { useAuth } from "react-oidc-context" ;
6
+
7
+ /*
8
+ On error with fetching data
9
+ try {
10
+ userManager.signinSilent()
11
+ } catch (error) {
12
+ userManager.signinRedirect()
13
+ }
14
+ */
15
+
16
+ export default function Review ( ) {
17
+ const auth = useAuth ( ) ;
18
+
19
+ return (
20
+ < div id = "review" className = { cn ( "mx-[20%]" ) } >
21
+ { auth . isLoading ? < Skeleton /> : < ReviewPage /> }
22
+ </ div >
23
+ ) ;
24
+ }
25
+
26
+ function ReviewPage ( ) {
27
+ const auth = useAuth ( ) ;
28
+
29
+ return (
30
+ < p >
31
+ Secret data that needs authentication { auth . isAuthenticated } { " " }
32
+ { auth . user ?. profile . email }
33
+ </ p >
34
+ ) ;
35
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import type { Metadata } from "next" ;
2
2
import "./globals.css" ;
3
3
import { cn } from "@/lib/utils" ;
4
- import { AuthProvider } from "react-oidc-context" ;
5
- import Footer from "../components/Footer" ;
4
+ import Footer from "@/components/Footer" ;
6
5
7
6
export const metadata : Metadata = {
8
7
title : "Penn Course Review" ,
9
8
description : "Made by Penn Labs" ,
10
9
} ;
11
10
12
- const oidcConfig = {
13
- authority : "<your authority>" ,
14
- clientId : "<your client id>" ,
15
- redirectUri : "<your redirect uri>" ,
16
- // ...
17
- } ;
18
-
19
11
export default function RootLayout ( {
20
12
children,
21
13
} : Readonly < {
@@ -24,10 +16,8 @@ export default function RootLayout({
24
16
return (
25
17
< html lang = "en" >
26
18
< body className = { cn ( "antialiased" , "flex" , "flex-col" ) } >
27
- < AuthProvider { ...oidcConfig } >
28
- { children }
29
- < Footer />
30
- </ AuthProvider >
19
+ { children }
20
+ < Footer />
31
21
</ body >
32
22
</ html >
33
23
) ;
Original file line number Diff line number Diff line change
1
+ export default function Skeleton ( ) {
2
+ return (
3
+ < div >
4
+ < h1 > Skeleton data</ h1 >
5
+ </ div >
6
+ ) ;
7
+ }
Original file line number Diff line number Diff line change 1
- const HOST_URL = process . env . NODE_ENV === 'development'
1
+ export const BASE_URL = process . env . NODE_ENV === 'development'
2
2
? 'http://localhost:3000'
3
- : process . env . NEXT_PUBLIC_HOST_URL ;
3
+ : process . env . NEXT_PUBLIC_BASE_URL ;
4
+
5
+ export const CLIENT_ID = process . env . NEXT_PUBLIC_CLIENT_ID ?? "" ;
4
6
5
7
export const doAPIRequest = ( path : string , options = { } ) : Promise < Response > =>
6
8
fetch ( `/api${ path } ` , options ) ;
7
9
8
10
export function getLogoutUrl ( ) : string {
9
11
return `/accounts/logout/?next=${ encodeURIComponent (
10
- `${ HOST_URL } /logout`
12
+ `${ BASE_URL } /logout`
11
13
) } `;
12
14
}
13
15
@@ -16,12 +18,3 @@ export function getLogoutUrl(): string {
16
18
// window.location.pathname
17
19
// )}`;
18
20
// }
19
-
20
- export async function checkAuth ( ) : Promise < boolean > {
21
- const res = await fetch ( "/accounts/me/" ) ;
22
- if ( res . status < 300 && res . status >= 200 ) {
23
- return true ;
24
- } else {
25
- return false ;
26
- }
27
- }
Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+ import { UserManager , WebStorageStateStore } from "oidc-client-ts" ;
3
+ import { BASE_URL , CLIENT_ID } from "@/lib/api" ;
4
+
5
+ export const userManager = new UserManager ( {
6
+ authority : "https://platform.pennlabs.org/" ,
7
+ client_id : CLIENT_ID ,
8
+ redirect_uri : `${ BASE_URL } /callback` ,
9
+ scope : "openid read" ,
10
+ metadataUrl :
11
+ "https://platform.pennlabs.org/accounts/.well-known/openid-configuration/" ,
12
+ metadata : {
13
+ authorization_endpoint :
14
+ "https://platform.pennlabs.org/accounts/authorize/" ,
15
+ token_endpoint : "https://platform.pennlabs.org/accounts/token/" ,
16
+ jwks_uri :
17
+ "https://platform.pennlabs.org/accounts/.well-known/jwks.json" ,
18
+ } ,
19
+ automaticSilentRenew : true ,
20
+ includeIdTokenInSilentRenew : true ,
21
+ userStore : new WebStorageStateStore ( { store : window ?. localStorage } ) ,
22
+ } ) ;
23
+ console . log ( userManager ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments