Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reauthenticate method #271

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add reauthenticate method
  • Loading branch information
grdsdev committed Mar 19, 2024
commit 7e85a86fb243ca2fa429ca3f11392db73f62527e
8 changes: 7 additions & 1 deletion Examples/Examples/HomeView.swift
Original file line number Diff line number Diff line change
@@ -15,12 +15,18 @@ struct HomeView: View {
var body: some View {
TodoListView()
.toolbar {
ToolbarItem(placement: .cancellationAction) {
ToolbarItemGroup(placement: .cancellationAction) {
Button("Sign out") {
Task {
try! await supabase.auth.signOut()
}
}

Button("Reauthenticate") {
Task {
try! await supabase.auth.reauthenticate()
}
}
}
}
.task {
7 changes: 7 additions & 0 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
@@ -811,6 +811,13 @@ public actor AuthClient {
.decoded(decoder: configuration.decoder)
}

/// Sends a re-authentication OTP to the user's email or phone number.
public func reauthenticate() async throws {
try await api.authorizedExecute(
Request(path: "/reauthenticate", method: .get)
)
}

/// Gets the current user details if there is an existing session.
/// - Parameter jwt: Takes in an optional access token jwt. If no jwt is provided, user() will
/// attempt to get the jwt from the current session.
10 changes: 10 additions & 0 deletions Tests/AuthTests/RequestsTests.swift
Original file line number Diff line number Diff line change
@@ -344,6 +344,16 @@ final class RequestsTests: XCTestCase {
}
}

func testReauthenticate() async {
sessionManager.returnSession = .success(.validSession)

let sut = makeSUT()

await assert {
try await sut.reauthenticate()
}
}

private func assert(_ block: () async throws -> Void) async {
do {
try await block()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl \
--header "Apikey: dummy.api.key" \
--header "Authorization: Bearer accesstoken" \
--header "X-Client-Info: gotrue-swift/x.y.z" \
"http://localhost:54321/auth/v1/reauthenticate"
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/openid/AppAuth-iOS.git",
"state" : {
"revision" : "269c90515328c24f90b2ed17a67c8a796b485448",
"version" : "1.7.2"
"revision" : "7e2c09cbeb3bb799f26c268dbedb26325ea722a9",
"version" : "1.7.3"
}
},
{
@@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "3ce83179e5f0c83ad54c305779c6b438e82aaf1d",
"version" : "1.2.1"
"revision" : "f01efb26f3a192a0e88dcdb7c3c391ec2fc25d9c",
"version" : "1.3.0"
}
},
{