Skip to content
New issue

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

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

Already on GitHub? # to your account

chore(auth): Move AuthScreen to use new session management #151

Merged
merged 1 commit into from
Oct 16, 2023
Merged
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
6 changes: 1 addition & 5 deletions src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

import { getServerSession } from 'next-auth'
import { Metadata } from 'next'

import { authOptions } from '@/app/api/auth/[...nextauth]/route'
import { AuthScreen } from '@/components/sw360'
import { Session } from '@/object-types'

export const metadata: Metadata = {
title: 'Welcome - SW360',
}

export default async function AuthPage() {
const session: Session = await getServerSession(authOptions)
return <AuthScreen session={session} />
return <AuthScreen />
}
17 changes: 7 additions & 10 deletions src/components/sw360/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,26 @@

'use client'

import { Alert, Button, Form, Modal } from 'react-bootstrap'
import { signIn } from 'next-auth/react'
import { signIn, useSession } from 'next-auth/react'
import { useLocale, useTranslations } from 'next-intl'
import Link from 'next-intl/link'
import { useRouter } from 'next/navigation'
import { useState } from 'react'
import Link from 'next-intl/link'
import { Alert, Button, Form, Modal } from 'react-bootstrap'

import { HttpStatus } from '@/object-types'
import { CREDENTIALS } from '@/object-types/Constants'
import { HttpStatus, Session } from '@/object-types'
import { LanguageSwitcher } from 'next-sw360'

interface Props {
session?: Session
}

const AuthScreen = ({ session }: Props) => {
function AuthScreen() {
const router = useRouter()
const locale = useLocale()
const t = useTranslations('default')
const [dialogShow, setDialogShow] = useState<boolean>(false)
const [messageShow, setMessageShow] = useState<boolean>(false)
const [emailAddress, setEmailAddress] = useState<string>('@sw360.org')
const [password, setPassword] = useState<string>('')
const { status } = useSession()

const handleClose = () => setDialogShow(false)
const handleShow = () => setDialogShow(true)
Expand Down Expand Up @@ -64,7 +61,7 @@ const AuthScreen = ({ session }: Props) => {
<p className='mt-3'>{t('SW360_INFO')}</p>
<hr className='my-4' />
<h3>{t('In order to go ahead, please # or create a new account!')}</h3>
{!session ? (
{status === 'unauthenticated' ? (
<div className='buttons'>
<span>
<a className='btn btn-primary btn-lg' role='button' onClick={handleShow}>
Expand Down