Implementing sign out
The signOut
method revokes the session on the frontend and on the backend. Calling this function without a valid session also yields a successful response.
- Web
- Mobile
- Via NPM
- Via Script Tag
import Session from "supertokens-web-js/recipe/session";
async function logout () {
await Session.signOut();
window.location.href = "/";
}
async function logout () {
await supertokensSession.signOut();
window.location.href = "/";
}
- React Native
- Android
- iOS
- Flutter
import SuperTokens from "supertokens-react-native";
async function logout () {
await SuperTokens.signOut();
// navigate to the login screen..
}
import android.app.Application
import com.supertokens.session.SuperTokens
class MainApplication: Application() {
fun logout() {
SuperTokens.signOut(this);
// navigate to the login screen..
}
}
import UIKit
import SuperTokensIOS
class ViewController: UIViewController {
func signOut() {
SuperTokens.signOut(completionHandler: {
error in
if error != nil {
// handle error
} else {
// Signed out successfully
}
})
}
}
import 'package:supertokens_flutter/supertokens.dart';
Future<void> signOut() async {
await SuperTokens.signOut(
completionHandler: (error) {
// handle error if any
}
);
}
- On success, the
signOut
function does not redirect the user to another page, so you must redirect the user yourself. - The
signOut
function calls the signout API exposed by the session recipe on the backend. - If you call the
signOut
function whilst the access token has expired, but the refresh token still exists, our SDKs will do an automatic session refresh before revoking the session.