Skip to content

Commit 77dc462

Browse files
committed
redirect to original page
1 parent 708b6b7 commit 77dc462

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎frontend/main/src/components/FirebaseAuth.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@firebase/auth';
1212
import { useAuth, useSigninCheck } from 'reactfire';
1313
import { Auth, User } from 'firebase/auth';
14+
import { useRouter } from 'next/router';
1415

1516
export const FirebaseAuth = ({
1617
full = true,
@@ -20,6 +21,8 @@ export const FirebaseAuth = ({
2021
const [email, setEmail] = useState('');
2122
const [password, setPassword] = useState('');
2223
const auth = useAuth();
24+
const router = useRouter();
25+
const pathBack = router?.query?.path;
2326

2427
let signInOptions = [];
2528
if (full) {
@@ -41,7 +44,7 @@ export const FirebaseAuth = ({
4144
}
4245
const uiConfig = {
4346
signInOptions,
44-
signInSuccessUrl: window.location.href,
47+
signInSuccessUrl: `${window.location.origin + (pathBack ? pathBack : '')}`,
4548
credentialHelper: 'none',
4649
tosUrl: `${window.location.origin}/terms-of-use`,
4750
// Privacy policy url/callback.
@@ -155,7 +158,6 @@ export const LoadingSpinner = () => {
155158
className="fill-basics-50 dark:fill-basics-500"
156159
/>
157160
</svg>
158-
Loading...
159161
</div>
160162
);
161163
};

‎frontend/main/src/components/user/AvatarMenu.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useAuth, useSigninCheck } from 'reactfire';
66
import dynamic from 'next/dynamic';
77
import { signOut } from '@/components/FirebaseAuth';
88
import ActiveLink from '@/components/ActiveLink';
9+
import { useRouter } from 'next/router';
910

1011
const AuthWrapper = dynamic<any>(
1112
() => import('@/components/FirebaseAuth').then((mod) => mod.AuthWrapper),
@@ -40,14 +41,19 @@ export default function AvatarMenu({
4041
}): JSX.Element {
4142
const auth = useAuth();
4243
const { data: signInCheckResult } = useSigninCheck();
43-
44+
const router = useRouter();
4445
return (
4546
<FirebaseFirestoreProvider>
4647
<>
4748
<div className="relative">
4849
<AuthWrapper
4950
fallback={
50-
<Link href="/user/profile">
51+
<Link
52+
href={
53+
`/user/profile` +
54+
(router.asPath === '/' ? '' : `?path=${router.asPath}`)
55+
}
56+
>
5157
<a className="flex items-center justify-center p-2 rounded text-basics-50 hover:bg-primary-800 dark:hover:bg-primary-800 focus:ring-2 focus:ring-basics-50">
5258
<svg
5359
width="20"

0 commit comments

Comments
 (0)