From eaf936e7758d33e54898da0e1121846e3f2d6e3a Mon Sep 17 00:00:00 2001 From: Willin Wang Date: Wed, 13 Dec 2023 23:17:24 +0800 Subject: [PATCH] chore: add site logout demo --- .changeset/khaki-lobsters-marry.md | 7 +++++++ apps/web/src/app.d.ts | 4 ++-- apps/web/src/components/ChangeRepo.svelte | 7 +++---- apps/web/src/routes/(zh)/auth/+page.md | 7 ++++--- apps/web/src/routes/en/auth/+page.md | 7 ++++--- apps/web/src/routes/logout/+page.server.ts | 7 +++++++ bun.lockb | Bin 336992 -> 336992 bytes package.json | 2 +- packages/auth/typedoc.json | 3 ++- packages/i18n/typedoc.json | 3 ++- .../src/lib/session/implements/cookie.ts | 8 +++++++- packages/session/typedoc.json | 1 + 12 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 .changeset/khaki-lobsters-marry.md create mode 100644 apps/web/src/routes/logout/+page.server.ts diff --git a/.changeset/khaki-lobsters-marry.md b/.changeset/khaki-lobsters-marry.md new file mode 100644 index 0000000..d9f0ba3 --- /dev/null +++ b/.changeset/khaki-lobsters-marry.md @@ -0,0 +1,7 @@ +--- +"@svelte-dev/session": patch +"@svelte-dev/auth": patch +"@svelte-dev/i18n": patch +--- + +fix session delete diff --git a/apps/web/src/app.d.ts b/apps/web/src/app.d.ts index f2f1ef8..e56d221 100644 --- a/apps/web/src/app.d.ts +++ b/apps/web/src/app.d.ts @@ -1,7 +1,7 @@ /// /// -import type { Auth } from '$lib/auth/auth.ts'; +import type { Auth } from '@svelte-dev/auth'; import type { SessionStorage } from '@svelte-dev/session'; // See https://kit.svelte.dev/docs/types#app @@ -11,7 +11,7 @@ declare global { // interface Error {} interface Locals { lang: string; - auth: Auth; + auth: Auth; session: SessionStorage<{ user: any }>; user?: | { diff --git a/apps/web/src/components/ChangeRepo.svelte b/apps/web/src/components/ChangeRepo.svelte index abf6e44..916a128 100644 --- a/apps/web/src/components/ChangeRepo.svelte +++ b/apps/web/src/components/ChangeRepo.svelte @@ -1,6 +1,5 @@ ![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38) @@ -29,6 +29,7 @@ Svelte Auth是一个完整的开源身份验证解决方案,适用于Svelte应 ## 演示 {#if $page && $page.data.user} +注销登录
{JSON.stringify($page.data.user, null, 2)}
@@ -176,8 +177,8 @@ export {}; 目前已经支持的策略有: -| Package | Meta | Changelog | -| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | +| Package | Meta | Changelog | +| ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | [@svelte-dev/auth-oauth2](https://github.com/willin/svelte-turbo/tree/main/packages/auth-oauth2/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-oauth2?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-oauth2) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-oauth2?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-oauth2) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-oauth2?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-oauth2) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-oauth2/CHANGELOG.md) | | [@svelte-dev/auth-github](https://github.com/willin/svelte-turbo/tree/main/packages/auth-github/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-github?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-github) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-github?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-github) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-github?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-github) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-github/CHANGELOG.md) | | [@svelte-dev/auth-alipay](https://github.com/willin/svelte-turbo/tree/main/packages/auth-alipay/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-alipay?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-alipay) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-alipay?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-alipay) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-alipay?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-alipay) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-alipay/CHANGELOG.md) | diff --git a/apps/web/src/routes/en/auth/+page.md b/apps/web/src/routes/en/auth/+page.md index 9810a3e..2f56d69 100644 --- a/apps/web/src/routes/en/auth/+page.md +++ b/apps/web/src/routes/en/auth/+page.md @@ -4,7 +4,7 @@ desc: A simple and easy-to-use Svelte identity management library --- ![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38) @@ -29,6 +29,7 @@ As with Passport.js, it uses the strategy pattern to support the different authe ## Demo {#if $page && $page.data.user} +Logout
{JSON.stringify($page.data.user, null, 2)}
@@ -175,8 +176,8 @@ export {}; ### Strategies -| Package | Meta | Changelog | -| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | +| Package | Meta | Changelog | +| ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | [@svelte-dev/auth-oauth2](https://github.com/willin/svelte-turbo/tree/main/packages/auth-oauth2/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-oauth2?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-oauth2) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-oauth2?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-oauth2) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-oauth2?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-oauth2) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-oauth2/CHANGELOG.md) | | [@svelte-dev/auth-github](https://github.com/willin/svelte-turbo/tree/main/packages/auth-github/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-github?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-github) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-github?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-github) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-github?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-github) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-github/CHANGELOG.md) | | [@svelte-dev/auth-alipay](https://github.com/willin/svelte-turbo/tree/main/packages/auth-alipay/) | [![npm](https://img.shields.io/npm/v/@svelte-dev/auth-alipay?style=flat-square&logo=npm)](https://npmjs.org/package/@svelte-dev/auth-alipay) [![npm](https://img.shields.io/npm/dm/@svelte-dev/auth-alipay?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-alipay) [![npm](https://img.shields.io/npm/dt/@svelte-dev/auth-alipay?style=flat-square&label=down)](https://npmjs.org/package/@svelte-dev/auth-alipay) | [Changelog](https://github.com/willin/svelte-turbo/tree/main/packages/auth-alipay/CHANGELOG.md) | diff --git a/apps/web/src/routes/logout/+page.server.ts b/apps/web/src/routes/logout/+page.server.ts new file mode 100644 index 0000000..e396432 --- /dev/null +++ b/apps/web/src/routes/logout/+page.server.ts @@ -0,0 +1,7 @@ +import type { Load } from '@sveltejs/kit'; + +export const load: Load = async ({ url, locals }) => { + throw await locals.auth.logout({ + redirectTo: url?.searchParams?.get('redirectTo') ?? '/' + }); +}; diff --git a/bun.lockb b/bun.lockb index c848cd753e6bc8f279f2b4bd68bc4d4e4ce4bfbe..658b0e0d2a1f2cab9a50fdb2768899e9b17ad570 100755 GIT binary patch delta 893 zcmaEGLgc{-kqLSVcehzh{*`6;^TWJHy97#H&zhWi_EIb|S-QwIeTjWnf7nL9RVI@y ztPCb=m-}h}*{{H)hORn`izc%UeC+*g|>=%~ZSyg&}v)vKDm~-4Ebw@(iw&+QInEuw1 zQKJ5HepHC4wPLNzA33&nyrIg6mUl3&+fw1NYo>$|W7UzL5}~iZNf%30FF51<`;Fdx zH;MCkQ>Sm`mpGW;CY{oytB?cy28TPT2do;B-7@KxKrdu!L31Qxqr0QE-TemnK+Y2Y(yTDI0cnlYiiC-*En zzT!5IPFVJm%~|m>lfqqdpw43f((K62+t!%ol7Fjg$IRpkzh&p1C#b)YVcEx}w{aEg z_u5@Hw>-I*==HIii%ZT6pLFQ)tDaJaOyR_^hMGJ3(t8iuI&*AW)c)6+5r~<#|Fvdr zFji!YGt@IQ)H7lbW@2FAXJBaPR+}~d{K6OWSQsG^)92+gOPU%nFqi-p@BtOv)kd-sySD VK)o;n)WNLwugWabzbdn40{~D)Q+faZ delta 890 zcmaEGLgc{-kqLSV@dx=m*Uz3*IcM3!6@R(Yd|GOmR@>~1;<`7rG187#Qf{N)DwD|- zsRolZOa;Jn29#a_rC&g44Kt`bgl=A8wta;eBP+ARvLv08=0+^@l2qCz_snTJ!nHeT zb@OVKsP2Vfx7MnOa2jY=nk=u|pgyPl^Hj6Ick?!FId%3)i`Gg0$KP+gz5V0I^tYCb z67|-8%q6n~vpz5U_rKoYTtS4QuH{RKi7V)e8Y>R^0kq!iV{I7dn->o zOaHuBYx!KoZ%?|eO?bcE;s^r+10w?iM+1;%24WasIdyf@>o+Z1#NWRvd%&@Dm)t4U zMn?zk;F}VMKj$rRo1?j{Vry87^#)1nFqL<&b`*WjURo~R@L0yii!)u6iFbQv=JdH% zKbriGhKifuW&WZPxtr3t!A*VKme;1fuEl@|h(~4H+0rfC~743U2b- zoImt{^(;&Q1A`M#Mi3|?HY*#2? zp0<(EaQb#dmW|Vsa#<9nuTy4Wn{Kbf!ZCfC5{opF*mWfqRV1#GGK)N%%R4=18" diff --git a/packages/auth/typedoc.json b/packages/auth/typedoc.json index 81532f9..351babb 100644 --- a/packages/auth/typedoc.json +++ b/packages/auth/typedoc.json @@ -10,8 +10,9 @@ "hideParameterTypesInTitle": false, "navigationLinks": { "Home": "https://svelte.js.cool/", - "I18n": "https://svelte.js.cool/docs/i18n", "Session": "https://svelte.js.cool/docs/session", + "Auth": "https://svelte.js.cool/docs/auth", + "I18n": "https://svelte.js.cool/docs/i18n", "GitHub": "https://github.com/willin/svelte-turbo", "NPM": "https://npmjs.com/package/@svelte-dev/auth", "Willin": "https://willin.wang" diff --git a/packages/i18n/typedoc.json b/packages/i18n/typedoc.json index 31fa778..0ea6626 100644 --- a/packages/i18n/typedoc.json +++ b/packages/i18n/typedoc.json @@ -10,8 +10,9 @@ "hideParameterTypesInTitle": false, "navigationLinks": { "Home": "https://svelte.js.cool/", - "Auth": "https://svelte.js.cool/docs/auth", "Session": "https://svelte.js.cool/docs/session", + "Auth": "https://svelte.js.cool/docs/auth", + "I18n": "https://svelte.js.cool/docs/i18n", "GitHub": "https://github.com/willin/svelte-turbo", "NPM": "https://npmjs.com/package/@svelte-dev/session", "Willin": "https://willin.wang" diff --git a/packages/session/src/lib/session/implements/cookie.ts b/packages/session/src/lib/session/implements/cookie.ts index b03ac34..a1cd4bc 100644 --- a/packages/session/src/lib/session/implements/cookie.ts +++ b/packages/session/src/lib/session/implements/cookie.ts @@ -106,7 +106,13 @@ export class CookieStrategy * Deletes data for a given session id from the data store. */ async deleteData(id: string): Promise { - this.#cookies.delete(id, this.#options); + if (!this.#chunk) { + return this.#cookies.delete(id, this.#options); + } + const allCookies = this.#cookies.getAll().filter((cookie) => cookie.name.startsWith(id)); + for (const cookie of allCookies) { + this.#cookies.delete(cookie.name, this.#options); + } } #chunkString(str: string, chunkSize: number) { diff --git a/packages/session/typedoc.json b/packages/session/typedoc.json index 823b9a4..be4d2ca 100644 --- a/packages/session/typedoc.json +++ b/packages/session/typedoc.json @@ -10,6 +10,7 @@ "hideParameterTypesInTitle": false, "navigationLinks": { "Home": "https://svelte.js.cool/", + "Session": "https://svelte.js.cool/docs/session", "Auth": "https://svelte.js.cool/docs/auth", "I18n": "https://svelte.js.cool/docs/i18n", "GitHub": "https://github.com/willin/svelte-turbo",