Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7532bbe6
Commit
7532bbe6
authored
Dec 07, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add return path for auth links
parent
1b6eb9cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
9 deletions
+17
-9
useLoginUrl.tsx
lib/hooks/useLoginUrl.tsx
+8
-0
useRedirectForInvalidAuthToken.tsx
lib/hooks/useRedirectForInvalidAuthToken.tsx
+4
-4
middleware.ts
middleware.ts
+1
-1
ProfileMenuDesktop.tsx
ui/snippets/profileMenu/ProfileMenuDesktop.tsx
+2
-2
ProfileMenuMobile.tsx
ui/snippets/profileMenu/ProfileMenuMobile.tsx
+2
-2
No files found.
lib/hooks/useLoginUrl.tsx
0 → 100644
View file @
7532bbe6
import
{
useRouter
}
from
'
next/router
'
;
import
link
from
'
lib/link/link
'
;
export
default
function
useLoginUrl
()
{
const
router
=
useRouter
();
return
link
(
'
auth
'
,
{},
{
path
:
router
.
asPath
});
}
lib/hooks/useRedirectForInvalidAuthToken.tsx
View file @
7532bbe6
...
@@ -5,7 +5,7 @@ import React from 'react';
...
@@ -5,7 +5,7 @@ import React from 'react';
import
{
QueryKeys
}
from
'
types/client/accountQueries
'
;
import
{
QueryKeys
}
from
'
types/client/accountQueries
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
link
from
'
lib/link/link
'
;
import
useLoginUrl
from
'
lib/hooks/useLoginUrl
'
;
export
interface
ErrorType
{
export
interface
ErrorType
{
error
?:
{
error
?:
{
...
@@ -19,6 +19,7 @@ export default function useRedirectForInvalidAuthToken() {
...
@@ -19,6 +19,7 @@ export default function useRedirectForInvalidAuthToken() {
const
state
=
queryClient
.
getQueryState
<
unknown
,
ErrorType
>
([
QueryKeys
.
profile
]);
const
state
=
queryClient
.
getQueryState
<
unknown
,
ErrorType
>
([
QueryKeys
.
profile
]);
const
errorStatus
=
state
?.
error
?.
error
?.
status
;
const
errorStatus
=
state
?.
error
?.
error
?.
status
;
const
loginUrl
=
useLoginUrl
();
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
if
(
errorStatus
===
401
)
{
if
(
errorStatus
===
401
)
{
...
@@ -26,9 +27,8 @@ export default function useRedirectForInvalidAuthToken() {
...
@@ -26,9 +27,8 @@ export default function useRedirectForInvalidAuthToken() {
if
(
apiToken
)
{
if
(
apiToken
)
{
Sentry
.
captureException
(
new
Error
(
'
Invalid api token
'
),
{
tags
:
{
source
:
'
fetch
'
}
});
Sentry
.
captureException
(
new
Error
(
'
Invalid api token
'
),
{
tags
:
{
source
:
'
fetch
'
}
});
const
authURL
=
link
(
'
auth
'
);
window
.
location
.
assign
(
loginUrl
);
window
.
location
.
assign
(
authURL
);
}
}
}
}
},
[
errorStatus
]);
},
[
errorStatus
,
loginUrl
]);
}
}
middleware.ts
View file @
7532bbe6
...
@@ -21,7 +21,7 @@ export function middleware(req: NextRequest) {
...
@@ -21,7 +21,7 @@ export function middleware(req: NextRequest) {
const
apiToken
=
req
.
cookies
.
get
(
NAMES
.
API_TOKEN
);
const
apiToken
=
req
.
cookies
.
get
(
NAMES
.
API_TOKEN
);
if
((
isAccountRoute
||
isProfileRoute
)
&&
!
apiToken
&&
appConfig
.
isAccountSupported
)
{
if
((
isAccountRoute
||
isProfileRoute
)
&&
!
apiToken
&&
appConfig
.
isAccountSupported
)
{
const
authUrl
=
link
(
'
auth
'
);
const
authUrl
=
link
(
'
auth
'
,
undefined
,
{
path
:
req
.
nextUrl
.
pathname
}
);
return
NextResponse
.
redirect
(
authUrl
);
return
NextResponse
.
redirect
(
authUrl
);
}
}
...
...
ui/snippets/profileMenu/ProfileMenuDesktop.tsx
View file @
7532bbe6
...
@@ -2,13 +2,13 @@ import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button } from '@c
...
@@ -2,13 +2,13 @@ import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button } from '@c
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
useFetchProfileInfo
from
'
lib/hooks/useFetchProfileInfo
'
;
import
useFetchProfileInfo
from
'
lib/hooks/useFetchProfileInfo
'
;
import
link
from
'
lib/link/link
'
;
import
useLoginUrl
from
'
lib/hooks/useLoginUrl
'
;
import
UserAvatar
from
'
ui/shared/UserAvatar
'
;
import
UserAvatar
from
'
ui/shared/UserAvatar
'
;
import
ProfileMenuContent
from
'
ui/snippets/profileMenu/ProfileMenuContent
'
;
import
ProfileMenuContent
from
'
ui/snippets/profileMenu/ProfileMenuContent
'
;
const
ProfileMenuDesktop
=
()
=>
{
const
ProfileMenuDesktop
=
()
=>
{
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
loginUrl
=
link
(
'
auth
'
);
const
loginUrl
=
useLoginUrl
(
);
return
(
return
(
<
Popover
openDelay=
{
300
}
placement=
"bottom-end"
gutter=
{
10
}
isLazy
>
<
Popover
openDelay=
{
300
}
placement=
"bottom-end"
gutter=
{
10
}
isLazy
>
...
...
ui/snippets/profileMenu/ProfileMenuMobile.tsx
View file @
7532bbe6
...
@@ -2,7 +2,7 @@ import { Flex, Box, Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclos
...
@@ -2,7 +2,7 @@ import { Flex, Box, Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclos
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
useFetchProfileInfo
from
'
lib/hooks/useFetchProfileInfo
'
;
import
useFetchProfileInfo
from
'
lib/hooks/useFetchProfileInfo
'
;
import
link
from
'
lib/link/link
'
;
import
useLoginUrl
from
'
lib/hooks/useLoginUrl
'
;
import
UserAvatar
from
'
ui/shared/UserAvatar
'
;
import
UserAvatar
from
'
ui/shared/UserAvatar
'
;
import
ColorModeToggler
from
'
ui/snippets/header/ColorModeToggler
'
;
import
ColorModeToggler
from
'
ui/snippets/header/ColorModeToggler
'
;
import
ProfileMenuContent
from
'
ui/snippets/profileMenu/ProfileMenuContent
'
;
import
ProfileMenuContent
from
'
ui/snippets/profileMenu/ProfileMenuContent
'
;
...
@@ -11,7 +11,7 @@ const ProfileMenuMobile = () => {
...
@@ -11,7 +11,7 @@ const ProfileMenuMobile = () => {
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
const
{
isOpen
,
onOpen
,
onClose
}
=
useDisclosure
();
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
{
data
,
isFetched
}
=
useFetchProfileInfo
();
const
loginUrl
=
link
(
'
auth
'
);
const
loginUrl
=
useLoginUrl
(
);
return
(
return
(
<>
<>
...
...
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