-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(auth): in memory code verifier storage (#296)
- Loading branch information
Showing
4 changed files
with
30 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
import ConcurrencyExtras | ||
import Foundation | ||
@_spi(Internal) import _Helpers | ||
|
||
struct CodeVerifierStorage: Sendable { | ||
var getCodeVerifier: @Sendable () throws -> String? | ||
var storeCodeVerifier: @Sendable (_ code: String) throws -> Void | ||
var deleteCodeVerifier: @Sendable () throws -> Void | ||
var get: @Sendable () -> String? | ||
var set: @Sendable (_ code: String?) -> Void | ||
} | ||
|
||
extension CodeVerifierStorage { | ||
static let live: Self = { | ||
@Dependency(\.configuration.localStorage) var localStorage | ||
|
||
let key = "supabase.code-verifier" | ||
let code = LockIsolated(String?.none) | ||
|
||
return Self( | ||
getCodeVerifier: { | ||
try localStorage.retrieve(key: key).flatMap { | ||
String(data: $0, encoding: .utf8) | ||
} | ||
}, | ||
storeCodeVerifier: { code in | ||
try localStorage.store(key: key, value: Data(code.utf8)) | ||
}, | ||
deleteCodeVerifier: { | ||
try localStorage.remove(key: key) | ||
} | ||
get: { code.value }, | ||
set: { code.setValue($0) } | ||
) | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters