-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update nextjs server actions with getAccessToken (#755)
- Loading branch information
Showing
8 changed files
with
101 additions
and
41 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
3 changes: 3 additions & 0 deletions
3
docs/quick-starts/framework/next-app-router/_server-actions-tip.mdx
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,3 @@ | ||
:::note | ||
It is not allowed to define inline "use server" annotated Server Actions in Client Components. We have to pass it down through props from a Server Component. | ||
::: |
2 changes: 1 addition & 1 deletion
2
...amework/next-app-router/api-resources/_fetch-access-token-for-api-resources.mdx
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
2 changes: 1 addition & 1 deletion
2
.../framework/next-app-router/api-resources/_fetch-organization-token-for-user.mdx
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
12 changes: 0 additions & 12 deletions
12
...k-starts/framework/next-app-router/api-resources/code/_get-access-token-code.md
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...-starts/framework/next-app-router/api-resources/code/_get-access-token-code.mdx
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,46 @@ | ||
import ServerActionsTip from '../../_server-actions-tip.mdx'; | ||
|
||
<ServerActionsTip /> | ||
|
||
```tsx title="app/page.ts" | ||
import { getAccessToken } from '@logto/next/server-actions'; | ||
import { logtoConfig } from './logto'; | ||
import GetAccessToken from './get-access-token'; | ||
|
||
export default async function Home() { | ||
return ( | ||
<main> | ||
<GetAccessToken | ||
onGetAccessToken={async () => { | ||
'use server'; | ||
|
||
return getAccessToken(logtoConfig, 'https://shopping.your-app.com/api'); | ||
}} | ||
/> | ||
</main> | ||
); | ||
} | ||
``` | ||
|
||
```tsx title="app/get-access-token.ts" | ||
'use client'; | ||
|
||
type Props = { | ||
onGetAccessToken: () => Promise<string>; | ||
}; | ||
|
||
const GetAccessToken = ({ onGetAccessToken }: Props) => { | ||
return ( | ||
<button | ||
onClick={async () => { | ||
const token = await onGetAccessToken(); | ||
console.log(token); | ||
}} | ||
> | ||
Get access token (see console log) | ||
</button> | ||
); | ||
}; | ||
|
||
export default GetAccessToken; | ||
``` |
27 changes: 0 additions & 27 deletions
27
...ework/next-app-router/api-resources/code/_get-organization-access-token-code.md
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...work/next-app-router/api-resources/code/_get-organization-access-token-code.mdx
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,46 @@ | ||
import ServerActionsTip from '../../_server-actions-tip.mdx'; | ||
|
||
<ServerActionsTip /> | ||
|
||
```tsx title="app/page.ts" | ||
import { getOrganizationToken } from '@logto/next/server-actions'; | ||
import { logtoConfig } from './logto'; | ||
import GetOrganizationToken from './get-organization-token'; | ||
|
||
export default async function Home() { | ||
return ( | ||
<main> | ||
<GetOrganizationToken | ||
onGetOrganizationToken={async () => { | ||
'use server'; | ||
|
||
return getOrganizationToken(logtoConfig, 'organization-id'); | ||
}} | ||
/> | ||
</main> | ||
); | ||
} | ||
``` | ||
|
||
```tsx title="app/get-organization-token.ts" | ||
'use client'; | ||
|
||
type Props = { | ||
onGetOrganizationToken: () => Promise<string>; | ||
}; | ||
|
||
const GetOrganizationToken = ({ onGetOrganizationToken }: Props) => { | ||
return ( | ||
<button | ||
onClick={async () => { | ||
const token = await onGetOrganizationToken(); | ||
console.log(token); | ||
}} | ||
> | ||
Get organization token (see console log) | ||
</button> | ||
); | ||
}; | ||
|
||
export default GetOrganizationToken; | ||
``` |