Skip to content

Commit e6d140f

Browse files
Resul AvanResul Avan
Resul Avan
authored and
Resul Avan
committed
wrong redirect fix
1 parent 57c894b commit e6d140f

File tree

7 files changed

+34
-133
lines changed

7 files changed

+34
-133
lines changed

src/components/navbar/ActionTopNavbar.vue

-48
This file was deleted.

src/components/navbar/TopNavbar.vue

+4-12
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,13 @@
3434

3535
<b-navbar-item v-else tag="div">
3636
<div class="buttons">
37-
<b-button
38-
tag="router-link"
39-
:to="routes.REGISTER"
40-
type="is-primary"
41-
>
37+
<a class="button is-primary" :href="routes.REGISTER.path">
4238
<strong>{{ $t('topNavbar.register') }}</strong>
43-
</b-button>
39+
</a>
4440

45-
<b-button
46-
tag="router-link"
47-
:to="routes.LOGIN"
48-
type="is-primary"
49-
>
41+
<a class="button is-primary" :href="routes.LOGIN.path">
5042
<strong>{{ $t('topNavbar.login') }}</strong>
51-
</b-button>
43+
</a>
5244
</div>
5345
</b-navbar-item>
5446
</template>

src/layouts/action.vue

-40
This file was deleted.

src/pages/auth/action.vue

+8-9
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,18 @@ import {
3333
import { getWarningNotificationMessage } from '~/service/notification-service'
3434
3535
@Component({
36-
components: {},
37-
layout: 'action'
36+
components: {}
3837
})
3938
export default class Action extends Vue {
40-
action: string = '';
41-
actionCode: string = '';
39+
action: string = ''
40+
actionCode: string = ''
4241
43-
isLoading = true;
44-
isFullPage = false;
42+
isLoading = true
43+
isFullPage = false
4544
46-
@StateNamespace.auth.Action handleVerifyEmail: (actionCode: string) => Promise<void>;
47-
@StateNamespace.auth.Action handleVerifyPasswordResetCode: (actionCode: string) => Promise<boolean>;
48-
@StateNamespace.notification.Action saveNotificationMessage: (notificationMessage: NotificationMessage) => {};
45+
@StateNamespace.auth.Action handleVerifyEmail: (actionCode: string) => Promise<void>
46+
@StateNamespace.auth.Action handleVerifyPasswordResetCode: (actionCode: string) => Promise<boolean>
47+
@StateNamespace.notification.Action saveNotificationMessage: (notificationMessage: NotificationMessage) => {}
4948
5049
asyncData ({ query }: Context) {
5150
const action = (query[FirebaseAuthActionParams.ACTION])

src/pages/auth/forget-password.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import ForgetPasswordForm from '~/components/form/ForgetPasswordForm.vue'
88
import { StateNamespace } from '~/types'
99
1010
@Component({
11-
components: { ForgetPasswordForm },
12-
layout: 'action'
11+
components: { ForgetPasswordForm }
1312
})
1413
export default class ForgetPassword extends Vue {
15-
@StateNamespace.auth.Action sendPasswordResetEmail: (code: any) => Promise<boolean>;
16-
@StateNamespace.notification.Action clearNotificationMessage: () => void;
14+
@StateNamespace.auth.Action sendPasswordResetEmail: (code: any) => Promise<boolean>
15+
@StateNamespace.notification.Action clearNotificationMessage: () => void
1716
1817
handleSendPasswordResetEmail (emailAddress: string) {
1918
this.clearNotificationMessage()

src/pages/auth/reset-password.vue

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ import { NotificationMessage, RouteParameters, StateNamespace } from '~/types'
2323
import { getWarningNotificationMessage } from '~/service/notification-service'
2424
2525
@Component({
26-
components: { SetPasswordForm },
27-
layout: 'action'
26+
components: { SetPasswordForm }
2827
})
2928
export default class ResetPassword extends Vue {
30-
actionCode: string = '';
29+
actionCode: string = ''
3130
32-
@StateNamespace.auth.Action confirmPasswordReset: (code: any) => {};
33-
@StateNamespace.notification.Action clearNotificationMessage: () => void;
34-
@StateNamespace.notification.Action saveNotificationMessage: (notificationMessage: NotificationMessage) => {};
31+
@StateNamespace.auth.Action confirmPasswordReset: (code: any) => {}
32+
@StateNamespace.notification.Action clearNotificationMessage: () => void
33+
@StateNamespace.notification.Action saveNotificationMessage: (notificationMessage: NotificationMessage) => {}
3534
3635
handleConfirmPasswordReset (password: string) {
3736
this.clearNotificationMessage()

src/plugins/firebase-auth-listener.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { Location, Route } from 'vue-router'
55
import { AppCookie, AppTokenType, AuthUser, FirebaseClaimKey } from 'types-module'
66
import { auth } from '~/plugins/fire-init-plugin'
77
import {
8-
LocalStorageKey,
8+
LocalStorageKey, LOGIN,
99
QueryParameters,
1010
Routes,
1111
sessionCookieOptionsDev,
1212
sessionCookieOptionsProd,
1313
StoreConfig
1414
} from '~/types'
15-
import { authenticatedAllowed, authenticatedNotAllowed } from '~/service/global-service'
15+
import { authenticatedAllowed, authenticatedNotAllowed, getUserRoute } from '~/service/global-service'
1616
import { getAuthUser } from '~/service/firebase/firebase-service'
1717
import { configureAxiosObservable, configureFcmObservable, loadNotificationObservable } from '~/service/rx-service'
1818

@@ -22,14 +22,15 @@ const forceLogout = (store: Store<any>) => {
2222
})
2323
}
2424

25-
const getNextRoute = (route: Route): Location => {
25+
const getNextRoute = (route: Route, authUser: AuthUser): Location => {
2626
const path: string = route.query[QueryParameters.NEXT] as string
27+
console.log(`firebaseAuthListenerPlugin next: ${path}, fullPath: ${route.fullPath}, route.path: ${route.path}`)
2728
if (path) {
2829
return { path }
2930
}
3031

3132
if (authenticatedNotAllowed(route) || route.path === Routes.ACTION.path) {
32-
return Routes.PROFILE
33+
return getUserRoute(Routes.PROFILE_DYNAMIC, authUser.username)
3334
}
3435

3536
return { path: route.fullPath }
@@ -40,17 +41,20 @@ const setRememberMe = async (store: Store<any>, app: NuxtAppOptions) => {
4041
await store.dispatch(StoreConfig.auth.saveRememberMe, rememberMe === undefined ? true : rememberMe)
4142
}
4243

43-
const updateAuthStore = async (firebaseUser: User|null, store: Store<any>) => {
44+
const updateAuthStore = async (firebaseUser: User, store: Store<any>) => {
4445
if (!firebaseUser) {
4546
store.commit(StoreConfig.auth.setAuthUser, null)
47+
return null
4648
}
47-
return await firebaseUser?.getIdTokenResult()
49+
50+
return await firebaseUser.getIdTokenResult()
4851
.then((idTokenResult) => {
4952
const authUser = getAuthUser(firebaseUser) as AuthUser
5053
if (authUser) {
5154
authUser.username = idTokenResult.claims[FirebaseClaimKey.USERNAME]
5255
store.commit(StoreConfig.auth.setAuthUser, authUser)
5356
}
57+
return authUser
5458
})
5559
}
5660

@@ -73,7 +77,7 @@ const firebaseAuthListenerPlugin: Plugin = ({ store, app, route, redirect }) =>
7377
console.log(error)
7478
})
7579

76-
auth.onAuthStateChanged((firebaseUser: User|null) => {
80+
auth.onAuthStateChanged((firebaseUser: User) => {
7781
return store.dispatch(StoreConfig.loading.saveLoading, true)
7882
.then(async () => {
7983
if (store.state.auth.forceLogout) {
@@ -82,11 +86,7 @@ const firebaseAuthListenerPlugin: Plugin = ({ store, app, route, redirect }) =>
8286
}
8387

8488
console.log('firebaseAuthListenerPlugin called with a user: ', !!firebaseUser)
85-
86-
await updateAuthStore(firebaseUser, store)
87-
.catch((error: Error) => {
88-
console.log(error)
89-
})
89+
const authUser = await updateAuthStore(firebaseUser, store)
9090

9191
if (firebaseUser) {
9292
await firebaseUser.getIdToken()
@@ -97,11 +97,11 @@ const firebaseAuthListenerPlugin: Plugin = ({ store, app, route, redirect }) =>
9797
configureFcmObservable.next()
9898
})
9999

100-
redirect(getNextRoute(route))
100+
redirect(getNextRoute(route, authUser))
101101
} else {
102102
logoutActions(store, app)
103103
if (authenticatedAllowed(route)) {
104-
redirect(Routes.LOGIN)
104+
location.replace(LOGIN.path)
105105
}
106106
}
107107
})

0 commit comments

Comments
 (0)