Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SSHOC
sshoc-marketplace-frontend
Commits
d59e2a73
Commit
d59e2a73
authored
Jul 07, 2021
by
Stefan Probst
Browse files
fix: ensure get user data is authenticated
parent
21f1e553
Pipeline
#210144
passed with stages
in 9 minutes and 56 seconds
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/api/sshoc/client.ts
View file @
d59e2a73
...
...
@@ -8,7 +8,8 @@ import type { UseMutationOptions, UseMutationResult } from 'react-query'
import
{
useMutation
}
from
'
react-query
'
import
type
{
ImplicitGrantTokenData
,
OAuthRegistrationDto
}
from
'
@/api/sshoc
'
import
{
baseUrl
,
request
}
from
'
@/api/sshoc
'
import
{
baseUrl
,
request
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
/**
* Sign in user with username and password.
...
...
@@ -191,3 +192,23 @@ export function getMediaFileUrl({ mediaId }: { mediaId: string }): string {
)
return
String
(
url
)
}
export
function
useCurrentUser
():
ReturnType
<
typeof
useGetLoggedInUser
>
{
const
auth
=
useAuth
()
return
useGetLoggedInUser
(
{
enabled
:
auth
.
session
?.
accessToken
!==
undefined
,
/** immediately sign out in case of error */
retry
:
false
,
/** cache until cache is cleared manually */
staleTime
:
Infinity
,
onError
()
{
auth
.
signOut
()
},
},
{
token
:
auth
.
session
?.
accessToken
,
},
)
}
src/components/item/DatasetCreateForm/DatasetCreateForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
DatasetCore
,
DatasetDto
}
from
'
@/api/sshoc
'
import
{
useCreateDataset
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useCreateDataset
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
DateFormSection
}
from
'
@/components/item/DateFormSection/DateFormSection
'
...
...
@@ -43,7 +44,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/DatasetEditForm/DatasetEditForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
DatasetCore
,
DatasetDto
}
from
'
@/api/sshoc
'
import
{
useGetLoggedInUser
,
useUpdateDataset
}
from
'
@/api/sshoc
'
import
{
useUpdateDataset
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
DateFormSection
}
from
'
@/components/item/DateFormSection/DateFormSection
'
...
...
@@ -48,7 +49,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/PublicationCreateForm/PublicationCreateForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
PublicationCore
,
PublicationDto
}
from
'
@/api/sshoc
'
import
{
useCreatePublication
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useCreatePublication
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
DateFormSection
}
from
'
@/components/item/DateFormSection/DateFormSection
'
...
...
@@ -43,7 +44,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/PublicationEditForm/PublicationEditForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
PublicationCore
,
PublicationDto
}
from
'
@/api/sshoc
'
import
{
useGetLoggedInUser
,
useUpdatePublication
}
from
'
@/api/sshoc
'
import
{
useUpdatePublication
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
DateFormSection
}
from
'
@/components/item/DateFormSection/DateFormSection
'
...
...
@@ -48,7 +49,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/ToolCreateForm/ToolCreateForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
ToolCore
,
ToolDto
}
from
'
@/api/sshoc
'
import
{
useCreateTool
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useCreateTool
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -41,7 +42,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/ToolEditForm/ToolEditForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
ToolCore
,
ToolDto
}
from
'
@/api/sshoc
'
import
{
useGetLoggedInUser
,
useUpdateTool
}
from
'
@/api/sshoc
'
import
{
useUpdateTool
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -46,7 +47,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
TrainingMaterialCore
,
TrainingMaterialDto
}
from
'
@/api/sshoc
'
import
{
useCreateTrainingMaterial
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useCreateTrainingMaterial
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -41,7 +42,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/TrainingMaterialEditForm/TrainingMaterialEditForm.tsx
View file @
d59e2a73
...
...
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
TrainingMaterialCore
,
TrainingMaterialDto
}
from
'
@/api/sshoc
'
import
{
useGetLoggedInUser
,
useUpdateTrainingMaterial
}
from
'
@/api/sshoc
'
import
{
useUpdateTrainingMaterial
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -46,7 +47,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/WorkflowCreateForm/WorkflowCreateForm.tsx
View file @
d59e2a73
...
...
@@ -10,11 +10,8 @@ import { Fragment, useEffect, useRef, useState } from 'react'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
StepCore
,
WorkflowCore
,
WorkflowDto
}
from
'
@/api/sshoc
'
import
{
useCreateStep
,
useCreateWorkflow
,
useGetLoggedInUser
,
}
from
'
@/api/sshoc
'
import
{
useCreateStep
,
useCreateWorkflow
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -59,7 +56,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/components/item/WorkflowEditForm/WorkflowEditForm.tsx
View file @
d59e2a73
...
...
@@ -10,12 +10,8 @@ import { Fragment, useEffect, useRef, useState } from 'react'
import
{
useQueryClient
}
from
'
react-query
'
import
type
{
StepCore
,
WorkflowCore
,
WorkflowDto
}
from
'
@/api/sshoc
'
import
{
useCreateStep
,
useGetLoggedInUser
,
useUpdateStep
,
useUpdateWorkflow
,
}
from
'
@/api/sshoc
'
import
{
useCreateStep
,
useUpdateStep
,
useUpdateWorkflow
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
}
from
'
@/api/sshoc/types
'
import
{
ActorsFormSection
}
from
'
@/components/item/ActorsFormSection/ActorsFormSection
'
import
{
MainFormSection
}
from
'
@/components/item/MainFormSection/MainFormSection
'
...
...
@@ -65,7 +61,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const
toast
=
useToast
()
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
handleErrors
=
useErrorHandlers
()
const
validateCommonFormFields
=
useValidateCommonFormFields
()
const
isAllowedToPublish
=
...
...
src/modules/auth/ProtectedScreen.tsx
View file @
d59e2a73
...
...
@@ -3,7 +3,7 @@ import type { PropsWithChildren } from 'react'
import
{
Fragment
,
useEffect
}
from
'
react
'
import
type
{
UserDto
}
from
'
@/api/sshoc
'
import
{
use
GetLoggedIn
User
}
from
'
@/api/sshoc
'
import
{
use
Current
User
}
from
'
@/api/sshoc
/client
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
export
default
function
ProtectedScreen
({
...
...
@@ -14,10 +14,7 @@ export default function ProtectedScreen({
}
>
):
JSX
.
Element
|
null
{
const
router
=
useRouter
()
const
{
session
}
=
useAuth
()
const
user
=
useGetLoggedInUser
(
{
enabled
:
session
?.
accessToken
!=
null
},
{
token
:
session
?.
accessToken
},
)
const
user
=
useCurrentUser
()
useEffect
(()
=>
{
if
(
session
===
null
||
!
hasAppropriateRole
(
roles
,
user
.
data
))
{
...
...
src/modules/auth/ProtectedView.tsx
View file @
d59e2a73
import
type
{
PropsWithChildren
}
from
'
react
'
import
{
Fragment
}
from
'
react
'
import
{
use
GetLoggedIn
User
}
from
'
@/api/sshoc
'
import
{
use
Current
User
}
from
'
@/api/sshoc
/client
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
export
default
function
ProtectedView
({
...
...
@@ -11,10 +11,7 @@ export default function ProtectedView({
roles
?:
Array
<
'
contributor
'
|
'
moderator
'
|
'
administrator
'
>
}
>
):
JSX
.
Element
|
null
{
const
{
session
}
=
useAuth
()
const
user
=
useGetLoggedInUser
(
{
enabled
:
session
?.
accessToken
!=
null
},
{
token
:
session
?.
accessToken
},
)
const
user
=
useCurrentUser
()
if
(
session
===
null
)
return
null
...
...
src/modules/page/PageHeader.tsx
View file @
d59e2a73
...
...
@@ -6,7 +6,8 @@ import { useRouter } from 'next/router'
import
type
{
PropsWithChildren
,
Ref
}
from
'
react
'
import
{
Fragment
,
useEffect
,
useState
}
from
'
react
'
import
{
useGetItemCategories
,
useGetLoggedInUser
}
from
'
@/api/sshoc
'
import
{
useGetItemCategories
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
,
ItemSearchQuery
}
from
'
@/api/sshoc/types
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
ProtectedView
from
'
@/modules/auth/ProtectedView
'
...
...
@@ -23,7 +24,6 @@ import { getSingularItemCategoryLabel } from '@/utils/getSingularItemCategoryLab
import
type
{
UrlObject
}
from
'
@/utils/useActiveLink
'
import
{
useActiveLink
}
from
'
@/utils/useActiveLink
'
import
{
Svg
as
Logo
}
from
'
@@/assets/images/logo-with-text.svg
'
/**
* Page header.
*/
...
...
@@ -243,19 +243,7 @@ function AuthButton() {
const
router
=
useRouter
()
const
auth
=
useAuth
()
const
{
data
:
user
}
=
useGetLoggedInUser
(
{
enabled
:
auth
.
session
?.
accessToken
!==
undefined
,
/** immediately sign out in case of error */
retry
:
false
,
onError
()
{
auth
.
signOut
()
},
},
{
token
:
auth
.
session
?.
accessToken
,
},
)
const
{
data
:
user
}
=
useCurrentUser
()
const
[
redirectPath
,
setRedirectPath
]
=
useState
(()
=>
{
const
path
=
getRedirectPath
(
router
.
asPath
)
if
(
path
===
undefined
)
return
undefined
...
...
src/screens/account/AccountScreen.tsx
View file @
d59e2a73
import
Link
from
'
next/link
'
import
{
Fragment
}
from
'
react
'
import
{
use
GetLoggedIn
User
}
from
'
@/api/sshoc
'
import
{
use
Current
User
}
from
'
@/api/sshoc
/client
'
import
{
Icon
}
from
'
@/elements/Icon/Icon
'
import
{
Svg
as
ActorsIcon
}
from
'
@/elements/icons/big/actors.svg
'
import
{
Svg
as
ContributedItemsIcon
}
from
'
@/elements/icons/big/contributed-items.svg
'
...
...
@@ -57,7 +57,7 @@ const fields = [
* My account screen.
*/
export
default
function
AccountScreen
():
JSX
.
Element
{
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
// just for typescript - user should always exist here
if
(
user
.
data
==
null
)
return
<
div
>
User not found
</
div
>
...
...
src/screens/account/ContributedItemsScreen.tsx
View file @
d59e2a73
...
...
@@ -6,7 +6,8 @@ import type { ChangeEvent, FormEvent, Key } from 'react'
import
{
Fragment
,
useEffect
,
useState
}
from
'
react
'
import
type
{
SearchItem
,
SearchItems
}
from
'
@/api/sshoc
'
import
{
useGetLoggedInUser
,
useSearchItems
}
from
'
@/api/sshoc
'
import
{
useSearchItems
}
from
'
@/api/sshoc
'
import
{
useCurrentUser
}
from
'
@/api/sshoc/client
'
import
type
{
ItemCategory
,
ItemSearchQuery
}
from
'
@/api/sshoc/types
'
import
{
ProgressSpinner
}
from
'
@/elements/ProgressSpinner/ProgressSpinner
'
import
{
Select
}
from
'
@/elements/Select/Select
'
...
...
@@ -39,7 +40,7 @@ export default function ContributedItemsScreen(): JSX.Element {
const
router
=
useRouter
()
const
query
=
sanitizeQuery
(
router
.
query
)
const
user
=
use
GetLoggedIn
User
()
const
user
=
use
Current
User
()
const
auth
=
useAuth
()
const
handleErrors
=
useErrorHandlers
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment