@@ -698,15 +698,23 @@ public final class AuthClient: Sendable {
698
698
/// If using ``SignOutScope/others`` scope, no ``AuthChangeEvent/signedOut`` event is fired.
699
699
/// - Parameter scope: Specifies which sessions should be logged out.
700
700
public func signOut( scope: SignOutScope = . global) async throws {
701
- do {
702
- // Make sure we have a valid session.
703
- _ = try await sessionManager. session ( )
701
+ guard let accessToken = currentSession? . accessToken else {
702
+ configuration. logger? . warning ( " signOut called without a session " )
703
+ return
704
+ }
705
+
706
+ if scope != . others {
707
+ await sessionManager. remove ( )
708
+ eventEmitter. emit ( . signedOut, session: nil )
709
+ }
704
710
705
- try await api. authorizedExecute (
711
+ do {
712
+ _ = try await api. execute (
706
713
. init(
707
714
url: configuration. url. appendingPathComponent ( " logout " ) ,
708
715
method: . post,
709
- query: [ URLQueryItem ( name: " scope " , value: scope. rawValue) ]
716
+ query: [ URLQueryItem ( name: " scope " , value: scope. rawValue) ] ,
717
+ headers: [ . init( name: " Authorization " , value: " Bearer \( accessToken) " ) ]
710
718
)
711
719
)
712
720
} catch {
@@ -720,11 +728,6 @@ public final class AuthClient: Sendable {
720
728
throw error
721
729
}
722
730
}
723
-
724
- if scope != . others {
725
- await sessionManager. remove ( )
726
- eventEmitter. emit ( . signedOut, session: nil )
727
- }
728
731
}
729
732
730
733
/// Log in an user given a User supplied OTP received via email.
0 commit comments