gh-XcodesOrg-XcodesApp/Xcodes/SettingsView.swift
Brandon Evans 5149e817da
Store credentials in the keychain
Like xcodes, storing the username in defaults so we know which item to look up in the keychain later. This also fixes the Xcode list update logic to not only validate the session but login with saved credentials if it fails.
2020-12-22 22:06:18 -07:00

40 lines
1.3 KiB
Swift

import AppleAPI
import SwiftUI
struct SettingsView: View {
@EnvironmentObject var appState: AppState
var body: some View {
VStack(alignment: .leading) {
GroupBox(label: Text("Apple ID")) {
VStack(alignment: .leading) {
if let username = Current.defaults.string(forKey: "username") {
Text(username)
Button("Sign Out", action: appState.logOut)
} else {
Button("Sign In", action: { self.appState.presentingSignInAlert = true })
.sheet(isPresented: $appState.presentingSignInAlert) {
SignInCredentialsView(isPresented: $appState.presentingSignInAlert)
.environmentObject(appState)
}
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
Spacer()
}
.padding()
.navigationTitle("Settings")
.frame(width: 300)
.frame(minHeight: 300)
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
Group {
SettingsView()
.environmentObject(AppState())
}
}
}