Skip to content

Commit

Permalink
chore: add site logout demo
Browse files Browse the repository at this point in the history
  • Loading branch information
willin committed Dec 13, 2023
1 parent 3d89578 commit eaf936e
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .changeset/khaki-lobsters-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@svelte-dev/session": patch
"@svelte-dev/auth": patch
"@svelte-dev/i18n": patch
---

fix session delete
4 changes: 2 additions & 2 deletions apps/web/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />

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
Expand All @@ -11,7 +11,7 @@ declare global {
// interface Error {}
interface Locals {
lang: string;
auth: Auth;
auth: Auth<unknown>;
session: SessionStorage<{ user: any }>;
user?:
| {
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/ChangeRepo.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
// @ts-nocheck
import { page } from '$app/stores';
import { linkPrefix } from '$lib/stores/prefix';
import { currentRepo } from '$lib/stores/repo';
Expand All @@ -13,13 +12,13 @@
class={`${className ?? 'animate-menu hidden lg:inline-flex menu menu-horizontal round'}`}
{...rest}>
<li aria-current={$currentRepo === 'session' ? 'repo' : undefined}>
<a class={itemClass} href={`${$linkPrefix}/session`}>Session</a>
<a class={itemClass} href={`${$linkPrefix || ''}/session`}>Session</a>
</li>
<li aria-current={$currentRepo === 'auth' ? 'repo' : undefined}>
<a class={itemClass} href={`${$linkPrefix}/auth`}>Auth</a>
<a class={itemClass} href={`${$linkPrefix || ''}/auth`}>Auth</a>
</li>
<li aria-current={$currentRepo === 'i18n' ? 'repo' : undefined}>
<a class={itemClass} href={`${$linkPrefix}/i18n`}>I18n</a>
<a class={itemClass} href={`${$linkPrefix || ''}/i18n`}>I18n</a>
</li>
</ul>

Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/routes/(zh)/auth/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ desc: 一个简单好用的 Svelte 身份管理库
---

<script>
import { page } from "$app/stores"
import { page } from "$app/stores";
</script>

![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38)
Expand All @@ -29,6 +29,7 @@ Svelte Auth是一个完整的开源身份验证解决方案,适用于Svelte应
## 演示

{#if $page && $page.data.user}
<a class="btn btn-secondary m-auto !w-32 !max-w-32 !min-w-0 flex" data-sveltekit-preload-data="tap" href="/logout">注销登录</a>

<div class="w-full">
<pre>{JSON.stringify($page.data.user, null, 2)}</pre>
Expand Down Expand Up @@ -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) |
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/routes/en/auth/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ desc: A simple and easy-to-use Svelte identity management library
---

<script>
import { page } from "$app/stores"
import { page } from "$app/stores";
</script>

![Logo](https://repository-images.githubusercontent.com/726691357/f09bf6fc-3844-4584-8eee-6bfb425d8a38)
Expand All @@ -29,6 +29,7 @@ As with Passport.js, it uses the strategy pattern to support the different authe
## Demo

{#if $page && $page.data.user}
<a class="btn btn-secondary m-auto !w-32 !max-w-32 !min-w-0 flex" href="/logout?redirectTo=/en">Logout</a>

<div class="w-full">
<pre>{JSON.stringify($page.data.user, null, 2)}</pre>
Expand Down Expand Up @@ -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) |
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/routes/logout/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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') ?? '/'
});
};
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint-staged": "latest",
"prettier": "^3.1.0",
"prettier-plugin-svelte": "^3.1.2",
"turbo": "latest"
"turbo": "^1.11.2"
},
"engines": {
"node": ">=18"
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion packages/session/src/lib/session/implements/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ export class CookieStrategy<Data = SessionData, FlashData = Data>
* Deletes data for a given session id from the data store.
*/
async deleteData(id: string): Promise<void> {
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) {
Expand Down
1 change: 1 addition & 0 deletions packages/session/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit eaf936e

Please sign in to comment.