Skip to content

Commit

Permalink
chore: Small lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Helio Chissini de Castro <heliocastro@gmail.com>
  • Loading branch information
heliocastro committed Nov 17, 2024
1 parent e54624e commit b55e473
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/app/[locale]/requests/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const metadata: Metadata = {
title: 'Requests',
}

async function RequestsPage() {
function RequestsPage(): JSX.Element {
return <Requests />
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ const sw360OauthPwdGrantTypeOption: NextAuthOptions = {
},
}

export default sw360OauthPwdGrantTypeOption
export default sw360OauthPwdGrantTypeOption
5 changes: 2 additions & 3 deletions src/app/api/session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import { getServerSession } from 'next-auth'
import { NextResponse } from 'next/server'
import authOptions from '../auth/[...nextauth]/authOptions'

export async function GET() {
export async function GET(): Promise<NextResponse> {
const session = await getServerSession(authOptions)

if (!session) {
return new NextResponse(JSON.stringify({ status: 'fail', message: 'You are not logged in' }), { status: 401 })
}

return NextResponse.json({
authenticated: !!session,
authenticated: true,
session,
})
}
1
27 changes: 14 additions & 13 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,42 @@ const generateToken = async (userData: UserCredentialInfo): Promise<null | AuthT
try {
const clientManagementURL: string = SW360_API_URL + '/authorization/client-management'
let credentials: string = Buffer.from(`${userData.username}:${userData.password}`).toString('base64')

const opts: RequestContent = { method: 'GET', headers: {}, body: null }

opts.headers['Content-Type'] = 'application/json'
opts.headers['Authorization'] = `Basic ${credentials}`

let oAuthClient: OAuthClient | null = null

const response = await fetch(clientManagementURL, opts)
if (response.status === HttpStatus.OK) {
const oauth_clients = await response.json() as Array<OAuthClient>
const oauth_clients = (await response.json()) as Array<OAuthClient>
oAuthClient = oauth_clients[0]
}

if (oAuthClient == null) {
return null
}

credentials = Buffer.from(`${oAuthClient.client_id}:${oAuthClient.client_secret}`, `binary`).toString('base64')

opts.headers['Authorization'] = `Basic ${credentials}`
const authorizationURL: string =
SW360_API_URL +
'/authorization/oauth/token?grant_type=password&username=' +
userData.username +
'&password=' +
userData.password

let sw360token: AuthToken | null = null
const tokenResponse = await fetch(authorizationURL, opts)
if (tokenResponse.status == HttpStatus.OK) {
sw360token = await tokenResponse.json() as AuthToken
}
sw360token = (await tokenResponse.json()) as AuthToken
}
return sw360token
} catch(e) {
} catch (e) {
console.log(e)
return null
}
}
Expand All @@ -65,4 +66,4 @@ const AuthService = {
generateBasicToken,
}

export default AuthService
export default AuthService
6 changes: 3 additions & 3 deletions src/services/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function enableSubscribing(id = defaultId): Observable<Message> {
}

// convenience methods
function success(message: string, options?: MessageOptions | undefined): void {
function success(message: string, options?: MessageOptions): void {
showMessage(MessageType.Success, message, 'Success', options)
}

function error(message: string, options?: MessageOptions | undefined): void {
function error(message: string, options?: MessageOptions): void {
showMessage(MessageType.Error, message, 'Error', options)
}

function info(message: string, options?: MessageOptions | undefined): void {
function info(message: string, options?: MessageOptions): void {
showMessage(MessageType.Info, message, 'Info', options)
}

Expand Down

0 comments on commit b55e473

Please sign in to comment.