注销
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.
1import { createClient } from '@supabase/supabase-js'23const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')45// ---cut---6async 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:
1import { createClient } from '@supabase/supabase-js'23const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...')45// ---cut---6// defaults to the global scope7await supabase.auth.signOut()89// sign out from the current session only10await 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.
被撤销会话的访问令牌在其过期时间之前仍然有效,这个时间编码在 exp 声明中。用户不会立即被登出,只有当访问令牌过期时才会被登出。
🌐 Access Tokens of revoked sessions remain valid until their expiry time, encoded in the exp claim. The user won't be immediately logged out and will only be logged out when the Access Token expires.