Skip to content
Auth

注销

Signing out a user

无论用户使用哪种方式登录,注销用户的方法都是一样的。

🌐 Signing out a user works the same way no matter what method they used to sign in.

从客户端库调用登出方法。它会移除活动会话并清除存储介质中的认证数据。

🌐 Call the sign out method from the client library. It removes the active session and clears Auth data from the storage medium.

1
import { createClient } from '@supabase/supabase-js'
2
3
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')
4
5
// ---cut---
6
async function signOut() {
7
const { error } = await supabase.auth.signOut()
8
}

登出和权限范围 #

🌐 Sign out and scopes

Supabase Auth 允许你在用户在你的应用中调用 sign out API 时指定三种不同的范围:

🌐 Supabase Auth allows you to specify three different scopes for when a user invokes the sign out API in your application:

  • global(默认)当用户的所有会话都被终止时。
  • local 只会终止用户当前的会话,但其他设备或浏览器上的会话仍然保持活跃。
  • others 用来终止该用户除当前会话外的所有会话。

你可以通过提供 scope 选项来调用它们:

🌐 You can invoke these by providing the scope option:

1
import { createClient } from '@supabase/supabase-js'
2
3
const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')
4
5
// ---cut---
6
// defaults to the global scope
7
await supabase.auth.signOut()
8
9
// sign out from the current session only
10
await supabase.auth.signOut({ scope: 'local' })

登出后,所有刷新令牌以及可能与受影响的会话相关的其他数据库对象都会被销毁,客户端库也会移除存储在本地存储介质中的会话。

🌐 Upon sign out, all refresh tokens and potentially other database objects related to the affected sessions are destroyed and the client library removes the session stored in the local storage medium.