mirror of
https://github.com/DerTyp7/f1r3wave-website.git
synced 2025-10-29 13:02:09 +01:00
Logout correctly
This commit is contained in:
@@ -4,7 +4,7 @@ import Credentials from 'next-auth/providers/credentials';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { authConfig } from './auth.config';
|
import { authConfig } from './auth.config';
|
||||||
|
|
||||||
export const { auth, signIn } = NextAuth({
|
export const { auth, signIn, signOut } = NextAuth({
|
||||||
...authConfig,
|
...authConfig,
|
||||||
providers: [
|
providers: [
|
||||||
Credentials({
|
Credentials({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import logo from '@/assets/logo_text.png';
|
import logo from '@/assets/logo_text.png';
|
||||||
import { logout } from '@/lib/actions';
|
import { performLogout } from '@/lib/actions';
|
||||||
import { getAuthStatus } from '@/lib/auth-utils';
|
import { getAuthStatus } from '@/lib/auth-utils';
|
||||||
import styles from '@/styles/Header.module.scss';
|
import styles from '@/styles/Header.module.scss';
|
||||||
import { faInstagram } from '@fortawesome/free-brands-svg-icons';
|
import { faInstagram } from '@fortawesome/free-brands-svg-icons';
|
||||||
@@ -41,8 +41,7 @@ export default function Header() {
|
|||||||
{isAuth ? (
|
{isAuth ? (
|
||||||
<p
|
<p
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await logout();
|
performLogout();
|
||||||
window.location.reload();
|
|
||||||
}}
|
}}
|
||||||
className={`${styles.navLink}`}>
|
className={`${styles.navLink}`}>
|
||||||
Logout
|
Logout
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { signIn } from '@/auth';
|
import { signIn, signOut } from '@/auth';
|
||||||
import { AuthError } from 'next-auth';
|
import { AuthError } from 'next-auth';
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
export async function authenticate(_prevState: string | undefined, formData: FormData): Promise<string> {
|
export async function authenticate(_prevState: string | undefined, formData: FormData): Promise<string> {
|
||||||
@@ -30,13 +29,7 @@ export async function authenticate(_prevState: string | undefined, formData: For
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function logout() {
|
export async function performLogout() {
|
||||||
const c = await cookies();
|
await signOut({ redirectTo: '/', redirect: true });
|
||||||
|
redirect('/');
|
||||||
c.delete('authjs.session-token');
|
|
||||||
c.delete('authjs.csrf-token');
|
|
||||||
c.delete('authjs.callback-url');
|
|
||||||
c.delete('__Host-authjs.csrf-token');
|
|
||||||
c.delete('__Secure-authjs.callback-url');
|
|
||||||
c.delete('__Secure-authjs.session-token');
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user