Skip to content

Commit

Permalink
endepunkt for å hente brukernavn
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Dec 27, 2023
1 parent 940acce commit 35d5248
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
7 changes: 7 additions & 0 deletions backend/src/main/kotlin/no/nav/spanner/Spanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.ktor.http.*
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.auth.jwt.*
import io.ktor.server.plugins.*
import io.ktor.server.plugins.callid.*
import io.ktor.server.plugins.callloging.*
Expand Down Expand Up @@ -84,6 +85,12 @@ fun Application.spanner(spleis: Personer, config: AzureADConfig, development: Bo
routing {
authenticate(optional = development) {
frontendRouting()
get("/api/meg") {
val principal = call.principal<JWTPrincipal>() ?: return@get call.respond(HttpStatusCode.Unauthorized)
val navn = principal["name"]
val ident = principal["NAVident"]
call.respondText("""{ "navn": "$navn", "ident": "$ident" } """, ContentType.Application.Json, HttpStatusCode.OK)
}
get("/api/person/") {
audit()
val (idType, idValue) = call.personId()
Expand Down
33 changes: 23 additions & 10 deletions frontend/src/components/søk/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ import React from 'react'
import {InternalHeader, Spacer} from "@navikt/ds-react";
import styles from './Header.module.css'
import classNames from "classnames";
import {useQuery} from "react-query";
import {Spinner} from "../Spinner";
import {Feilmelding} from "../Feilmelding";

export const Header: React.FC<object> = ({ children }) => (
<InternalHeader data-theme="spanner">
<InternalHeader.Title href="/">
<span className={classNames(styles.SpannSpan)}>🪣</span>er
</InternalHeader.Title>
{children}
<Spacer/>
<InternalHeader.User name="Ola Normann"/>
</InternalHeader>
)
export const Header: React.FC<object> = ({ children }) => {
const hentBrukerinfo = async() => {
return await fetch("/api/meg")
.then(response => response.json())
}
const { isLoading, isError, data, error } = useQuery(['brukerinfo'], hentBrukerinfo)

const navn = isLoading ? '[laster]' : isError ? '[feil]' : data.navn
const ident = isLoading ? '[laster]' : isError ? '[feil]' : data.ident
return (
<InternalHeader data-theme="spanner">
<InternalHeader.Title href="/">
<span className={classNames(styles.SpannSpan)}>🪣</span>er
</InternalHeader.Title>
{children}
<Spacer/>
<InternalHeader.User name={ navn } description={ ident }/>
</InternalHeader>
)
}
Header.displayName = 'Header'

0 comments on commit 35d5248

Please sign in to comment.