-
-
Notifications
You must be signed in to change notification settings - Fork 57
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When I use the following code in an API route it works and shows the user is Unauthorized prints our that it's isAuthorised:false
// pages/api/protected-resource.ts
import { logtoClient } from '../../../lib/logto';
export default logtoClient.withLogtoApiRoute(
(request, response) => {
console.log(request.user);
if (!request.user.isAuthenticated) {
response.status(401).json({ message: 'Unauthorized' });
return;
}
// Access token can be obtained from request.user.accessToken
response.json({
data: 'this_is_protected_resource',
});
},
{ getAccessToken: true, resource: 'https://drn1.com.au' }
);
But when I do it in pages/staff for a client end view it prints our that it's isAuthorised:true
/pages/staff/protected.ts
import { LogtoContext } from '@logto/next';
import { logtoClient } from '../../lib/logto';
type Props = {
user: LogtoContext;
};
const Profile = ({ user }: Props) => {
return <div>{user?.claims?.sub}</div>;
};
export default Profile;
export const getServerSideProps = logtoClient.withLogtoSsr(
async function ({ req }) {
const { user } = req;
// Access token can be obtained from user.accessToken
console.log(JSON.stringify(user));
return {
props: { user },
};
},
{ getAccessToken: true, resource: 'https://drn1.com' }
);
Context
OS: Mac OS
Environment: Localhost (nextJS)
Logto version: 1.0.0
Node version: v16.15.1
npm version: v8.11.0
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working

