Skip to content

Commit

Permalink
Merge branch 'main' into fix-solid-start
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 authored Feb 15, 2024
2 parents 609d980 + dbaa2e7 commit 4900dcc
Show file tree
Hide file tree
Showing 104 changed files with 2,748 additions and 447 deletions.
7 changes: 7 additions & 0 deletions .github/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ nextauthjs/next-auth-example:
deleteOrphaned: true
- .github/FUNDING.yml
- LICENSE

nextauthjs/next-auth-pages-example:
- source: apps/examples/nextjs-pages
dest: .
deleteOrphaned: true
- .github/FUNDING.yml
- LICENSE
36 changes: 26 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Init
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/[email protected]
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"
Expand All @@ -88,33 +88,49 @@ jobs:
if: ${{ github.repository == 'nextauthjs/next-auth' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
- name: Build
run: pnpm build
- name: Run tests
- name: Run unit tests
if: false
run: pnpm test
timeout-minutes: 15
env:
UPSTASH_REDIS_URL: ${{ secrets.UPSTASH_REDIS_URL }}
UPSTASH_REDIS_KEY: ${{ secrets.UPSTASH_REDIS_KEY }}
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(pnpx playwright -V | awk '{ print $2 }')" >> $GITHUB_ENV
- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright
if: steps.playwright-cache.outputs.cache-hit != 'true' && github.repository == 'nextauthjs/next-auth'
run: |
pnpm exec playwright install --with-deps chromium
- name: Run E2E tests
continue-on-error: true # TODO: Make this less flakey
if: github.repository == 'nextauthjs/next-auth'
timeout-minutes: 15
run: |
pnpm exec playwright install --with-deps > /dev/null 2>&1
pnpm test:e2e
timeout-minutes: 15
env:
AUTH_SECRET: ${{ secrets.AUTH_SECRET }}
TEST_KEYCLOAK_USERNAME: ${{ secrets.TEST_KEYCLOAK_USERNAME }}
TEST_KEYCLOAK_PASSWORD: ${{ secrets.TEST_KEYCLOAK_PASSWORD }}
AUTH_KEYCLOAK_ID: ${{ secrets.AUTH_KEYCLOAK_ID }}
AUTH_KEYCLOAK_SECRET: ${{ secrets.AUTH_KEYCLOAK_SECRET }}
AUTH_KEYCLOAK_ISSUER: ${{ secrets.AUTH_KEYCLOAK_ISSUER }}
AUTH_TRUST_HOST: 1
- uses: actions/upload-artifact@v3
name: Upload Playwright report
- uses: actions/upload-artifact@v4
name: Upload Playwright artifacts
with:
name: playwright-report
path: packages/core/playwright-report/
retention-days: 30
name: playwright-traces
path: "**/packages/utils/test-results/*/trace.zip"
retention-days: 7
- uses: codecov/codecov-action@v3
if: always()
name: Coverage
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Nissuer
uses: balazsorban44/nissuer@1.8.2
uses: balazsorban44/nissuer@1.9.2
with:
label-area-prefix: ""
label-area-section: "[Provider|Adapter] type(.*)### Environment"
label-comments: '{ "incomplete": ".github/invalid-reproduction.md", "good first issue": ".github/good-first-issue.md" }'
reproduction-link-section: "### Reproduction URL(.*)### Describe the issue"
reproduction-invalid-label: "invalid reproduction"
reproduction-issue-labels: "bug"
reproduction-issue-labels: "bug,"
reproduction-blocklist: "github.com/nextauthjs.*"
40 changes: 32 additions & 8 deletions apps/dev/nextjs/app/client.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
"use client"

import { signIn, useSession } from "next-auth/react"
import { signIn, signOut, useSession } from "next-auth/react"

export default function Client() {
const { data: session, update, status } = useSession()
return (
<div>
<pre>
{status === "loading" ? "Loading..." : JSON.stringify(session, null, 2)}
</pre>
<button onClick={() => signIn("github")}>Sign in</button>
<button onClick={() => signIn("credentials", {})}>Sign in cred</button>
<button onClick={() => update(`New Name`)}>Update session</button>
<div className="card">
<div className="card-header">
<h3>Client Component</h3>
</div>
<div className="card-body">
<h4>Session</h4>
<pre>
{status === "loading"
? "Loading..."
: JSON.stringify(session, null, 2)}
</pre>
<div className="btn-wrapper">
{session ? (
<>
<button
onClick={() => update({ user: { name: "Client Fill Murray" } })}
>
Update Session - New Name
</button>
<button onClick={() => signOut()}>Sign out</button>
</>
) : (
<>
<button onClick={() => signIn("github")}>Sign in Github</button>
<button onClick={() => signIn("credentials", {})}>
Sign in Credentials
</button>
</>
)}
</div>
</div>
</div>
)
}
17 changes: 3 additions & 14 deletions apps/dev/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ export default function RootLayout(props: { children: React.ReactNode }) {
<body>
<AppHeader />
<main>{props.children}</main>
<div>
<form
action={async () => {
"use server"
update({ user: { name: "New Name" } })
}}
>
<button>Update name</button>
</form>
</div>
<Footer />
</body>
</html>
Expand All @@ -34,10 +24,10 @@ export async function AppHeader() {
session={session}
signIn={
<form
action={async (formData) => {
action={async () => {
"use server"
try {
await signIn("credentials", formData)
await signIn()
} catch (error) {
if (error instanceof AuthError) {
console.log(error)
Expand All @@ -46,7 +36,6 @@ export async function AppHeader() {
}
}}
>
<input name="password" />
<button className={styles.buttonPrimary}>Sign in</button>
</form>
}
Expand All @@ -57,7 +46,7 @@ export async function AppHeader() {
await signOut()
}}
>
<button className={styles.button}>Sign out</button>
<button className={styles.buttonPrimary}>Sign out</button>
</form>
}
/>
Expand Down
37 changes: 29 additions & 8 deletions apps/dev/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
import { auth, unstable_update as update } from "auth"
import { SessionProvider } from "next-auth/react"
import { auth } from "auth"
import Client from "./client"

export default async function Page() {
const session = await auth()
return (
<>
<div className="container">
<h1>NextAuth.js Example</h1>
<p>
This is an example site to demonstrate how to use{" "}
<a href="https://nextjs.authjs.dev">NextAuth.js</a> for authentication.
</p>
<div className="card">
<div className="card-header">
<h3>Server Action</h3>
</div>
<div className="card-body">
{session ? (
<form
action={async () => {
"use server"
update({ user: { name: "Server Fill Murray" } })
}}
>
<button>Update Session - New Name</button>
</form>
) : null}
</div>
<div className="card-footer">
Note: The "Sign in" button in the header is using{" "}
<b>server form actions</b>.
</div>
</div>
{/*
NOTE: The `auth()` result is not run through the `session` callback, be careful passing down data
to a client component, this will be exposed via the /api/auth/session endpoint
*/}
<SessionProvider session={session} basePath="/auth">
<Client />
</SessionProvider>
<h1>NextAuth.js Example</h1>
<p>
This is an example site to demonstrate how to use{" "}
<a href="https://nextjs.authjs.dev">NextAuth.js</a> for authentication.
</p>
</>
</div>
)
}
92 changes: 90 additions & 2 deletions apps/dev/nextjs/app/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ body {
"Segoe UI Emoji",
"Segoe UI Symbol",
"Noto Color Emoji";
padding: 0 1rem 1rem 1rem;
max-width: 680px;
max-width: 960px;
margin: 0 auto;
background: #fff;
color: var(--color-text);
height: 100dvh;
display: flex;
flex-direction: column;
}

li,
p {
line-height: 1.5rem;
margin: 0;
}

a {
Expand All @@ -42,3 +45,88 @@ iframe {
border-radius: 0.5rem;
filter: invert(1);
}

h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0;
}

main {
flex-grow: 1;

@media screen and (max-width: 960px) {
padding: 0 1rem;
}
}

.container {
display: flex;
flex-direction: column;
gap: 1rem;
align-items: stretch;
justify-content: flex-start;
}

.card {
border-radius: 0.75rem;
background-color: #f3f3f3;

.card-header {
border-radius: 0.75rem 0.75rem 0 0;
background-color: #dfdfdf;
padding: 1.1rem;
}

.card-body {
padding-bottom: 1.1rem;

&:has(button) {
padding: 1.1rem;
}
}

.card-footer {
padding: 1.1rem;
padding-top: 0;
color: #777;
font-style: italic;
}

pre {
background-color: #ccc;
padding: 1rem;
border-radius: 0.5rem;
word-break: break-all;
white-space: pre-wrap;
}

.btn-wrapper {
display: flex;
gap: 1rem;
}

button {
justify-self: end;
font-weight: 500;
border-radius: 0.5rem;
border: none;
font-weight: bold;
cursor: pointer;
font-size: 1rem;
line-height: 1.4rem;
padding: 0.7rem 0.8rem;
position: relative;
z-index: 10;
background-color: #d5d5d5;
color: black;
text-decoration: none;
padding: 0.7rem 1.4rem;
}
button:hover {
background-color: #ccc;
}
}
12 changes: 9 additions & 3 deletions apps/dev/nextjs/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ declare module "next-auth" {
}

interface User {
foo: string
foo?: string
}
}

export default {
debug: false,
providers: [
Credentials({
credentials: { password: { label: "Password", type: "password" } },
authorize(c) {
if (c.password !== "password") return null
return {
id: "test",
foo: "bar",
name: "Test User",
email: "[email protected]",
}
Expand All @@ -50,6 +48,14 @@ export default {
if (trigger === "update") token.name = session.user.name
return token
},
async session({ session, token, trigger }) {
return {
...session,
user: {
...token,
},
}
},
},
basePath: "/auth",
} satisfies NextAuthConfig
Loading

0 comments on commit 4900dcc

Please sign in to comment.