Skip to content

Commit

Permalink
🐛 Remove all cookies when signing out thus fixing account switching
Browse files Browse the repository at this point in the history
Apparently, the Stud.IP API also stores session cookies that have a
higher precedence than my OAuth header…
  • Loading branch information
stoeffn committed Mar 22, 2018
1 parent 6cdf11b commit 7d74930
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion StudApp/StudKit/Api/Api.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Api<Routes: ApiRoutes> {

// MARK: - Life Cycle

private let session: URLSession
let session: URLSession

/// Base `URL` of all requests this instance issues. Any route paths will be appended to it.
var baseUrl: URL?
Expand Down
4 changes: 2 additions & 2 deletions StudApp/StudKit/Models/Users/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ public final class User: NSManagedObject, CDCreatable, CDIdentifiable, CDSortabl
// MARK: - Core Data Operations

extension User {
private static var currentUserFromDefaults: User? = {
private static var currentUserFromDefaults: User? {
let storageService = ServiceContainer.default[StorageService.self]
let coreDataService = ServiceContainer.default[CoreDataService.self]
let currentUserId = storageService.defaults.string(forKey: UserDefaults.userIdKey)
guard let user = try? fetch(byId: currentUserId, in: coreDataService.viewContext) else { return nil }
return user
}()
}

public internal(set) static var current: User? = currentUserFromDefaults {
didSet {
Expand Down
1 change: 1 addition & 0 deletions StudApp/StudKit/StudIp/StudIpService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class StudIpService {
func signOut() {
try? (api.authorizing as? PersistableApiAuthorizing)?.removeCredentials()

api.session.configuration.httpCookieStorage?.removeCookies(since: .distantPast)
api.baseUrl = nil
api.authorizing = nil

Expand Down

0 comments on commit 7d74930

Please sign in to comment.