Skip to content

Commit 77d9da5

Browse files
committed
Deprecate access to default JSONEncoder and JSONDecoder
1 parent 35c9cb0 commit 77d9da5

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public actor AuthClient {
5353
service: "supabase.gotrue.swift",
5454
accessGroup: nil
5555
)
56-
self.encoder = encoder ?? .goTrue
57-
self.decoder = decoder ?? .goTrue
56+
self.encoder = encoder ?? .auth
57+
self.decoder = decoder ?? .auth
5858
self.fetch = fetch
5959
}
6060
}

Sources/Auth/Deprecated.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Guilherme Souza on 14/12/23.
66
//
77

8+
import Foundation
9+
810
@available(*, deprecated, renamed: "AuthClient")
911
public typealias GoTrueClient = AuthClient
1012

@@ -19,3 +21,25 @@ public typealias GoTrueMetaSecurity = AuthMetaSecurity
1921

2022
@available(*, deprecated, renamed: "AuthError")
2123
public typealias GoTrueError = AuthError
24+
25+
extension JSONEncoder {
26+
@available(
27+
*,
28+
deprecated,
29+
message: "Access to the default JSONEncoder instance will be removed on the next major release, please use your own instance of JSONEncoder."
30+
)
31+
public static var goTrue: JSONEncoder {
32+
auth
33+
}
34+
}
35+
36+
extension JSONDecoder {
37+
@available(
38+
*,
39+
deprecated,
40+
message: "Access to the default JSONDecoder instance will be removed on the next major release, please use your own instance of JSONDecoder."
41+
)
42+
public static var goTrue: JSONDecoder {
43+
auth
44+
}
45+
}

Sources/Auth/Internal/SessionStorage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ extension SessionStorage {
3838
return Self(
3939
getSession: {
4040
try localStorage.retrieve(key: "supabase.session").flatMap {
41-
try JSONDecoder.goTrue.decode(StoredSession.self, from: $0)
41+
try JSONDecoder.auth.decode(StoredSession.self, from: $0)
4242
}
4343
},
4444
storeSession: {
45-
try localStorage.store(key: "supabase.session", value: JSONEncoder.goTrue.encode($0))
45+
try localStorage.store(key: "supabase.session", value: JSONEncoder.auth.encode($0))
4646
},
4747
deleteSession: {
4848
try localStorage.remove(key: "supabase.session")

Sources/Auth/Types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ private let dateFormatter = { () -> ISO8601DateFormatter in
602602
}()
603603

604604
extension JSONDecoder {
605-
public static let goTrue = { () -> JSONDecoder in
605+
static let auth = { () -> JSONDecoder in
606606
let decoder = JSONDecoder()
607607
decoder.keyDecodingStrategy = .convertFromSnakeCase
608608
decoder.dateDecodingStrategy = .custom { decoder in
@@ -626,7 +626,7 @@ extension JSONDecoder {
626626
}
627627

628628
extension JSONEncoder {
629-
public static let goTrue = { () -> JSONEncoder in
629+
static let auth = { () -> JSONEncoder in
630630
let encoder = JSONEncoder()
631631
encoder.keyEncodingStrategy = .convertToSnakeCase
632632
encoder.dateEncodingStrategy = .custom { date, encoder in

0 commit comments

Comments
 (0)