From 36ccf819bd28d35c1776659da0e831f2f7f2b270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Sat, 18 Feb 2023 18:56:57 +0100 Subject: [PATCH] Change endpoints.logout to nullable Add redirect_uri in logout route --- src/module.ts | 4 ++-- src/runtime/composables/useAuth.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/module.ts b/src/module.ts index b135003..cd014ba 100644 --- a/src/module.ts +++ b/src/module.ts @@ -12,7 +12,7 @@ export interface ModuleOptions { endpoints: { authorization: string, userInfo: string, - logout: string + logout: string | null }, clientId: string, scope: string[] @@ -28,7 +28,7 @@ const defaults: ModuleOptions = { endpoints: { authorization: 'https://accounts.bitinflow.com/oauth/authorize', userInfo: `https://accounts.bitinflow.com/api/v3/user`, - logout: 'https://accounts.bitinflow.com/logout' + logout: null, }, clientId: 'please-set-client-id', scope: ['user:read'] diff --git a/src/runtime/composables/useAuth.ts b/src/runtime/composables/useAuth.ts index 9b92d00..e8b9418 100644 --- a/src/runtime/composables/useAuth.ts +++ b/src/runtime/composables/useAuth.ts @@ -45,7 +45,17 @@ export default async (options: ComposableOptions = { accessToken.value = null; user.value = null; - return navigateTo(authConfig.endpoints.logout || authConfig.redirect.logout) + if (authConfig.endpoints.logout) { + // create oauth logout url + const params = new URLSearchParams({ + client_id: authConfig.clientId, + redirect_uri: window.location.origin + authConfig.redirect.logout + }) + + window.location.href = `${authConfig.endpoints.logout}?${params.toString()}` + } + + return navigateTo(authConfig.redirect.logout) } const setBearer = async (token: string, tokenType: string, expires: number) => {