Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: google auth route initialization #273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vue-user/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const __dzangolabVueUserTranslations = Symbol.for(

const plugin: Plugin = {
install: (app: App, options: DzangolabVueUserPluginOptions): void => {
updateRouter(options.router, options.config?.user?.routes);
updateRouter(options.router, options.config?.user);

initSupertokens(options.config);

Expand Down
14 changes: 9 additions & 5 deletions packages/vue-user/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PasswordResetRequestAcknowledge from "./views/PasswordResetRequestAcknowl
import Profile from "./views/Profile.vue";
import Signup from "./views/Signup.vue";

import type { RouteOverride, RouteOverrides } from "./types";
import type { DzangolabVueUserConfig, RouteOverride } from "./types";
import type { RouteMeta, RouteRecordRaw } from "vue-router";

const _routes = {
Expand Down Expand Up @@ -65,8 +65,12 @@ const getRoute = (
} as RouteRecordRaw;
};

const addRoutes = (router: Router, routes?: RouteOverrides) => {
router.addRoute(getRoute(_routes.google, routes?.google));
const addRoutes = (router: Router, user?: DzangolabVueUserConfig) => {
const routes = user?.routes;

if (user?.socialLogins?.includes("google")) {
router.addRoute(getRoute(_routes.google, routes?.google));
}

router.addRoute(getRoute(_routes.login, routes?.login));

Expand Down Expand Up @@ -128,8 +132,8 @@ const addAuthenticationGuard = (router: Router) => {
});
};

const updateRouter = (router: Router, routes?: RouteOverrides) => {
addRoutes(router, routes);
const updateRouter = (router: Router, user?: DzangolabVueUserConfig) => {
addRoutes(router, user);

addAuthenticationGuard(router);

Expand Down
2 changes: 1 addition & 1 deletion packages/vue-user/src/types/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface RouteOverride {
}

interface RouteOverrides {
google: RouteOverride;
google?: RouteOverride;
home?: string;
login: RouteOverride;
signup: RouteOverride & { disabled?: boolean };
Expand Down