File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
app/app/user-settings/[user_id] Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export default function UserSettingsPage({
7
7
params : { user_id : string } ;
8
8
} ) {
9
9
return (
10
- < AuthPageWrapper requireLoggedIn >
10
+ < AuthPageWrapper requireLoggedIn userId = { params . user_id } >
11
11
< UserSettings userId = { params . user_id } /> ;
12
12
</ AuthPageWrapper >
13
13
) ;
Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ import { useAuth } from "@/app/auth/auth-context";
6
6
import { Button } from "@/components/ui/button" ;
7
7
import { useRouter } from "next/navigation" ;
8
8
9
- type AuthCheck = ( user : { isAdmin : boolean } | undefined | null ) => boolean ;
9
+ type AuthCheck = (
10
+ user : { id : string ; isAdmin : boolean } | undefined | null
11
+ ) => boolean ;
10
12
11
13
interface AuthPageWrapperProps extends React . HTMLProps < HTMLDivElement > {
12
14
children : ReactNode ;
15
+ userId ?: string ;
13
16
14
17
// User access rules
15
18
authCheck ?: AuthCheck ; // Custom predicate which is true when user is to be granted access
@@ -19,20 +22,24 @@ interface AuthPageWrapperProps extends React.HTMLProps<HTMLDivElement> {
19
22
20
23
const AuthPageWrapper : React . FC < AuthPageWrapperProps > = ( {
21
24
children,
25
+ userId,
22
26
...props
23
27
} ) => {
24
28
const auth = useAuth ( ) ;
25
29
const router = useRouter ( ) ;
26
30
27
31
const authCheck = (
28
- user : { isAdmin : boolean } | undefined | null
32
+ user : { id : string ; isAdmin : boolean } | undefined | null
29
33
) : boolean => {
30
34
if ( props ?. requireLoggedIn && ! user ) {
31
35
return false ;
32
36
}
33
37
if ( props ?. requireAdmin && ! user ?. isAdmin ) {
34
38
return false ;
35
39
}
40
+ if ( userId && user ?. id !== userId ) {
41
+ return false ;
42
+ }
36
43
if ( props ?. authCheck ) {
37
44
return props . authCheck ( user ) ;
38
45
}
@@ -53,7 +60,9 @@ const AuthPageWrapper: React.FC<AuthPageWrapperProps> = ({
53
60
< Button
54
61
size = "lg"
55
62
onClick = { ( ) => {
56
- auth ?. user ? router . push ( "/" ) : router . push ( "/auth/login" ) ;
63
+ auth ?. user
64
+ ? router . push ( "/app/questions" )
65
+ : router . push ( "/auth/login" ) ;
57
66
} }
58
67
>
59
68
Return Home
You can’t perform that action at this time.
0 commit comments