Skip to content

Commit

Permalink
implement session auth login logic and cleanup views
Browse files Browse the repository at this point in the history
  • Loading branch information
sadnub committed Sep 18, 2024
1 parent 64daf29 commit 12095a7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
23 changes: 16 additions & 7 deletions src/ee/sso/api/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ function postForm(url: string, data: FormData) {
f.submit();
}

export interface MetaIsAuthenticated {
is_authenticated: boolean;
}

// sso providers
export interface AllAuthResponse<T> {
data: T;
status: number;
meta?: MetaIsAuthenticated;
}

export async function fetchSSOProviders(): Promise<SSOProvider> {
Expand All @@ -60,8 +65,14 @@ export async function removeSSOProvider(id: number) {
return data;
}

export async function getCurrentSession() {
const { data } = await axios.get("_allauth/browser/v1/auth/session");
export async function getSSOProviderToken() {
const { data } = await axios.post(
`${baseUrl}/ssoproviders/token/`,
{},
{
headers: { "X-CSRFToken": getCSRFToken() },
},
);
return data;
}

Expand All @@ -72,12 +83,10 @@ export interface SSOProviderConfig {
name: string;
}

export interface SSOConfigResponseProviders {
providers: SSOProviderConfig[];
}

export interface SSOConfigResponse {
socialaccount: SSOConfigResponseProviders;
socialaccount: {
providers: SSOProviderConfig[];
};
}

export async function getSSOConfig(): Promise<
Expand Down
4 changes: 2 additions & 2 deletions src/ee/sso/components/SSOProvidersTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ import { fetchSSOProviders, removeSSOProvider } from "@/ee/sso/api/sso";
import { notifySuccess } from "@/utils/notify";
// ui imports
import SSOProvidersForm from "@/components/modals/coresettings/SSOProvidersForm.vue";
import SSOProvidersForm from "@/ee/sso/components/SSOProvidersForm.vue";
// types
import { type SSOProvider } from "@/types/accounts";
import { type SSOProvider } from "@/ee/sso/types/sso";
// setup quasar
const $q = useQuasar();
Expand Down
17 changes: 5 additions & 12 deletions src/ee/sso/views/ProviderCallback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ const router = useRouter();
const auth = useAuthStore();
if (!error) {
auth
.checkSessionAuth()
.then((r) => {
// auth was successful
console.log(r);
router.push({ name: "Dashboard" });
})
.catch((e) => {
// auth was not successful
console.error(e);
router.push({ name: "Login" });
});
if (auth.loggedIn) {
router.push({ name: "Dashboard" });
} else {
router.push({ name: "Login" });
}
}
</script>
5 changes: 0 additions & 5 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ const routes = [
name: "SessionExpired",
component: () => import("@/views/SessionExpired.vue"),
},
{
path: "/account/provider/callback",
name: "ProviderCallback",
component: () => import("@/ee/sso/views/ProviderCallback.vue"),
},
{ path: "/:catchAll(.*)", component: () => import("@/views/NotFound.vue") },
];

Expand Down
6 changes: 0 additions & 6 deletions src/stores/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineStore } from "pinia";
import { useStorage } from "@vueuse/core";
import { getCurrentSession } from "@/ee/sso/api/sso";

import axios from "axios";

Expand Down Expand Up @@ -68,10 +67,5 @@ export const useAuthStore = defineStore("auth", {
const { data } = await axios.post("/accounts/users/setup_totp/");
return data;
},
async checkSessionAuth() {
const result = await getCurrentSession();
console.log(result);
return result;
},
},
});
3 changes: 0 additions & 3 deletions src/views/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import { useRouter } from "vue-router";
import {
openSSOProviderRedirect,
getSSOConfig,
getCurrentSession,
type SSOProviderConfig,
} from "@/ee/sso/api/sso";
Expand Down Expand Up @@ -157,8 +156,6 @@ async function onSubmit() {
onMounted(async () => {
const result = await getSSOConfig();
ssoProviders.value = result.data.socialaccount.providers;
await getCurrentSession();
});
</script>

Expand Down

0 comments on commit 12095a7

Please sign in to comment.