Skip to content

Commit e93e43e

Browse files
committed
feat: next-auth upgrade to 5
1 parent 1efc0b5 commit e93e43e

26 files changed

+197
-322
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ Create a file called `.env.local` in the root of the project and add the followi
1616

1717
```bash
1818
# next-auth environment variables
19-
NEXTAUTH_DEBUG="<true|false>"
20-
NEXTAUTH_SECRET="<given-secret>"
21-
NEXTAUTH_URL="<given-base-url>"
19+
AUTH_DEBUG="<true|false>"
20+
AUTH_SECRET="<given-secret>" # generate a secret using `pnpm exec auth secret`
2221

2322
# shibboleth oidc environment variables
2423
SHIBBOLETH_OIDC_ISSUER_URL="<given-issuer-url>"

__tests__/app/errorDescription.test.ts

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,6 @@ import { describe, it, expect } from 'vitest';
22
import { getAuthErrorDescription } from '@/app/errorDescription';
33

44
describe('errorDescription', () => {
5-
it('OAuthSignin should return value', () => {
6-
expect(getAuthErrorDescription('OAuthSignin')).toEqual(
7-
'Error in constructing an authorization URL.',
8-
);
9-
});
10-
11-
it('OAuthCallback should return value', () => {
12-
expect(getAuthErrorDescription('OAuthCallback')).toEqual(
13-
'Error in handling the response from an OAuth provider.',
14-
);
15-
});
16-
17-
it('OAuthCreateAccount should return value', () => {
18-
expect(getAuthErrorDescription('OAuthCreateAccount')).toEqual(
19-
'Could not create OAuth provider user in the database.',
20-
);
21-
});
22-
23-
it('EmailCreateAccount should return value', () => {
24-
expect(getAuthErrorDescription('EmailCreateAccount')).toEqual(
25-
'Could not create email provider user in the database.',
26-
);
27-
});
28-
29-
it('Callback should return value', () => {
30-
expect(getAuthErrorDescription('Callback')).toEqual(
31-
'Error in the OAuth callback handler route.',
32-
);
33-
});
34-
35-
it('OAuthAccountNotLinked should return value', () => {
36-
expect(getAuthErrorDescription('OAuthAccountNotLinked')).toEqual(
37-
'If the email on the account is already linked, but not with this OAuth account.',
38-
);
39-
});
40-
41-
it('EmailSignin should return value', () => {
42-
expect(getAuthErrorDescription('EmailSignin')).toEqual(
43-
'Sending the e-mail with the verification token failed.',
44-
);
45-
});
46-
47-
it('CredentialsSignin should return value', () => {
48-
expect(getAuthErrorDescription('CredentialsSignin')).toEqual(
49-
"The authorize callback returned null in the Credentials provider. We don't recommend providing information about which part of the credentials were wrong, as it might be abused by malicious hackers.",
50-
);
51-
});
52-
53-
it('SessionRequired should return value', () => {
54-
expect(getAuthErrorDescription('SessionRequired')).toEqual(
55-
'The content of this page requires you to be signed in at all times. See useSession for configuration.',
56-
);
57-
});
58-
595
it('Configuration should return value', () => {
606
expect(getAuthErrorDescription('Configuration')).toEqual(
617
'There is a problem with the server configuration. Check if your options are correct.',
@@ -74,15 +20,15 @@ describe('errorDescription', () => {
7420
);
7521
});
7622

77-
it('default should return value', () => {
78-
expect(getAuthErrorDescription('')).toEqual(
79-
'Catch all, will apply, if none of the other errors matched.',
23+
it('Default should return value', () => {
24+
expect(getAuthErrorDescription('EmailCreateAccount')).toEqual(
25+
'Catch all, will apply, if none of the above matched.',
8026
);
8127
});
8228

8329
it('default should return value', () => {
8430
expect(getAuthErrorDescription(null)).toEqual(
85-
'Catch all, will apply, if none of the other errors matched.',
31+
'Catch all, will apply, if none of the above matched.',
8632
);
8733
});
8834
});

__tests__/app/not-found.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { cleanup, render, screen } from '@testing-library/react';
44

55
describe('NotFound', () => {
66
beforeEach(() => {
7-
render(NotFound());
7+
render(<NotFound />);
88
});
99

1010
it('should exists', () => {

__tests__/app/page.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { afterEach, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
22
import { cleanup, render, screen } from '@testing-library/react';
33
import Page from '../../app/page';
4-
import { getServerSession } from 'next-auth';
4+
import { auth } from '@/auth';
55

6-
vi.mock('next-auth', () => ({
7-
getServerSession: vi.fn(),
6+
vi.mock('@/auth', () => ({
7+
auth: vi.fn(),
88
}));
99

1010
describe('Home, when user is not authenticated', () => {
1111
beforeEach(async () => {
12-
(getServerSession as Mock).mockReturnValue(null);
12+
(auth as Mock).mockReturnValue(null);
1313
render(await Page());
1414
});
1515

@@ -44,7 +44,7 @@ describe('Home, when user is authenticated', () => {
4444
};
4545

4646
beforeEach(async () => {
47-
(getServerSession as Mock).mockReturnValue(Promise.resolve(session));
47+
(auth as Mock).mockReturnValue(Promise.resolve(session));
4848
render(await Page());
4949
});
5050

__tests__/app/ui/__snapshots__/navbar.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`Navbar, when user is authenticated > Button should match snapshot 1`] =
44
<button
55
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
66
tabindex="0"
7-
type="button"
7+
type="submit"
88
>
99
Abmelden
1010
<span
@@ -46,7 +46,7 @@ exports[`Navbar, when user is not authenticated > Button should match snapshot 1
4646
<button
4747
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
4848
tabindex="0"
49-
type="button"
49+
type="submit"
5050
>
5151
Anmelden
5252
<span

__tests__/app/ui/__snapshots__/signInButton.test.tsx.snap

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ exports[`SignInButton > should match snapshot 1`] = `
44
<button
55
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
66
tabindex="0"
7-
type="button"
7+
type="submit"
8+
>
9+
Anmelden
10+
<span
11+
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
12+
/>
13+
</button>
14+
`;
15+
16+
exports[`SignInButton 1`] = `
17+
<button
18+
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
19+
tabindex="0"
20+
type="submit"
821
>
922
Anmelden
1023
<span

__tests__/app/ui/__snapshots__/signOutButton.test.tsx.snap

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ exports[`SignOutButton > should match snapshot 1`] = `
44
<button
55
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
66
tabindex="0"
7-
type="button"
7+
type="submit"
8+
>
9+
Abmelden
10+
<span
11+
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
12+
/>
13+
</button>
14+
`;
15+
16+
exports[`SignOutButton 1`] = `
17+
<button
18+
class="MuiButtonBase-root MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit MuiButton-root MuiButton-outlined MuiButton-outlinedInherit MuiButton-sizeMedium MuiButton-outlinedSizeMedium MuiButton-colorInherit css-sbfmij-MuiButtonBase-root-MuiButton-root"
19+
tabindex="0"
20+
type="submit"
821
>
922
Abmelden
1023
<span

__tests__/app/ui/authErrorView.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('AuthErrorView', () => {
1818
};
1919
});
2020

21-
render(AuthErrorView());
21+
render(<AuthErrorView />);
2222
});
2323

2424
it('should exists', () => {

__tests__/app/ui/navbar.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { afterEach, beforeEach, describe, expect, it, Mock, vi } from 'vitest';
22
import { cleanup, render, screen } from '@testing-library/react';
3-
import { getServerSession } from 'next-auth';
43
import Navbar from '@/app/ui/navbar';
4+
import { auth } from '@/auth';
55

6-
vi.mock('next-auth', () => ({
7-
getServerSession: vi.fn(),
6+
vi.mock('@/auth', () => ({
7+
auth: vi.fn(),
88
}));
99

1010
describe('Navbar, when user is not authenticated', () => {
1111
beforeEach(async () => {
12-
(getServerSession as Mock).mockReturnValue(null);
12+
(auth as Mock).mockReturnValue(null);
1313
render(await Navbar());
1414
});
1515

@@ -56,7 +56,7 @@ describe('Navbar, when user is authenticated', () => {
5656
};
5757

5858
beforeEach(async () => {
59-
(getServerSession as Mock).mockReturnValue(Promise.resolve(session));
59+
(auth as Mock).mockReturnValue(Promise.resolve(session));
6060
render(await Navbar());
6161
});
6262

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2-
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
1+
import { expect, test, vi } from 'vitest';
2+
import { fireEvent, render, screen } from '@testing-library/react';
33
import SignInButton from '@/app/ui/signInButton';
44

5-
describe('SignInButton', () => {
6-
beforeEach(() => {
7-
render(SignInButton());
8-
});
9-
10-
it('should exists', () => {
11-
expect(screen.getByRole('button')).toBeDefined();
12-
});
13-
14-
it('should match snapshot', () => {
15-
expect(screen.getByRole('button')).toMatchSnapshot();
16-
});
17-
18-
it('should trigger signOut function', () => {
19-
const { mockedSignIn } = vi.hoisted(() => {
20-
return { mockedSignIn: vi.fn(() => Promise.resolve()) };
21-
});
22-
vi.mock('next-auth/react', () => {
23-
return { signIn: mockedSignIn };
24-
});
25-
26-
fireEvent.click(screen.getByText(/Anmelden/));
27-
expect(mockedSignIn).toHaveBeenCalledOnce();
28-
});
29-
30-
afterEach(() => {
31-
cleanup();
5+
test('SignInButton', () => {
6+
vi.mock('@/auth', () => {
7+
return { signIn: vi.fn(() => Promise.resolve()) };
328
});
9+
render(<SignInButton />);
10+
expect(screen.getByRole('button')).toBeDefined();
11+
expect(screen.getByRole('button')).toMatchSnapshot();
12+
fireEvent.click(screen.getByText(/Anmelden/));
3313
});

0 commit comments

Comments
 (0)