Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples/auth): removes all client-side auth from rsc app #6258

Draft
wants to merge 4 commits into
base: beta
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use client'

import type { User } from '@/payload-types'

import Link from 'next/link'
import React from 'react'

import { useAuth } from '../../../_providers/Auth'
import classes from './index.module.scss'

export const HeaderNav: React.FC = () => {
const { user } = useAuth()

export const HeaderNav: React.FC<{
user?: User | null
}> = ({ user }) => {
return (
<nav
className={[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { headers as getHeaders } from 'next/headers'
import Image from 'next/image'
import Link from 'next/link'
import React from 'react'

import { getUser } from '../../_utilities/getUser'
import { Gutter } from '../Gutter'
import { HeaderNav } from './Nav'
import classes from './index.module.scss'

export function Header() {
export async function Header() {
const headers = getHeaders()
const user = await getUser(headers)

return (
<header className={classes.header}>
<Gutter className={classes.wrap}>
Expand All @@ -24,7 +29,7 @@ export function Header() {
/>
</picture>
</Link>
<HeaderNav />
<HeaderNav user={user} />
</Gutter>
</header>
)
Expand Down

This file was deleted.

34 changes: 0 additions & 34 deletions examples/auth/payload/src/app/(app)/_providers/Auth/gql.ts

This file was deleted.

186 changes: 0 additions & 186 deletions examples/auth/payload/src/app/(app)/_providers/Auth/index.tsx

This file was deleted.

34 changes: 0 additions & 34 deletions examples/auth/payload/src/app/(app)/_providers/Auth/rest.ts

This file was deleted.

35 changes: 0 additions & 35 deletions examples/auth/payload/src/app/(app)/_providers/Auth/types.ts

This file was deleted.

16 changes: 16 additions & 0 deletions examples/auth/payload/src/app/(app)/_utilities/getUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use server'
import type { User } from '@/payload-types'

import { getPayloadHMR } from '@payloadcms/next/utilities'
import { unstable_cache } from 'next/cache'

import config from '../../../payload.config'

export const getUser = unstable_cache(
async (headers: Headers): Promise<User | null> => {
const payload = await getPayloadHMR({ config })
const { user } = await payload.auth({ headers })
return user
},
['payload-user'],
)
Loading