aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-01-06 20:14:19 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-01-06 20:14:19 -0500
commitd773afa32ac58be36a82fcdd7bb41ac2629f8c2c (patch)
treec29e6368f095a7a4dca22901fbc72db72878d33e
parent3bd7effc15d0b87adce01281b073aa1db67d3cba (diff)
missed optional logout url
-rw-r--r--lib/vnlib.browser/src/social/index.ts24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/vnlib.browser/src/social/index.ts b/lib/vnlib.browser/src/social/index.ts
index 121fb50..d4f9f2a 100644
--- a/lib/vnlib.browser/src/social/index.ts
+++ b/lib/vnlib.browser/src/social/index.ts
@@ -72,7 +72,7 @@ export interface SocialLoginApi<T>{
export interface SocialOAuthPortal {
readonly id: string;
readonly login: string;
- readonly logout: string;
+ readonly logout?: string;
}
/**
@@ -87,7 +87,7 @@ export const useSocialOauthLogin = <T extends OAuthMethod>(methods: T[], axiosCo
const axios = useAxios(axiosConfig);
//A cookie will hold the status of the current login method
- const c = new Cookies(null, { path: '/', sameSite: 'strict', httpOnly:false });
+ const c = new Cookies(null, { sameSite: 'strict', httpOnly:false });
const getNonceQuery = () => new URLSearchParams(window.location.search).get('nonce');
const getResultQuery = () => new URLSearchParams(window.location.search).get('result');
@@ -155,11 +155,13 @@ export const useSocialOauthLogin = <T extends OAuthMethod>(methods: T[], axiosCo
throw new Error('The current session has not been initialized for social login');
}
+ const loginUrl = method.loginUrl();
+
//Prepare the session for a new login
const login = await prepareLogin();
//Send a post request to the endpoint to complete the login and pass the nonce argument
- const { data } = await axios.post<ITokenResponse>(method.loginUrl(), { ...login, nonce })
+ const { data } = await axios.post<ITokenResponse>(loginUrl, { ...login, nonce })
//Verify result
data.getResultOrThrow()
@@ -173,7 +175,7 @@ export const useSocialOauthLogin = <T extends OAuthMethod>(methods: T[], axiosCo
}
//Set the cookie to the method id
- c.set(cookieName, method.Id);
+ c.set(cookieName, method.Id, { path: loginUrl });
}
const logout = async (): Promise<boolean> => {
@@ -245,9 +247,13 @@ export const createSocialMethod = (id: string, path: MaybeRef<string>): OAuthMet
* Creates social OAuth methods from the given portals (usually captured from the server)
*/
export const fromPortals = (portals: SocialOAuthPortal[]): OAuthMethod[] => {
- return map(portals, p => ({
- Id: p.id,
- loginUrl: () => p.login,
- getLogoutData: () => ({ url: p.logout, args: {} })
- }))
+ return map(portals, p => {
+ const method = createSocialMethod(p.id, p.login);
+
+ //If a logout url is defined, then add it to the method
+ if(p.logout){
+ method.getLogoutData = () => ({ url: p.logout!, args: {} })
+ }
+ return method;
+ })
}