Skip to content

Commit

Permalink
Merge pull request #1344 from PrefectHQ/enhancement-logout-route-2022…
Browse files Browse the repository at this point in the history
…-11-01

Enhancement: Add explicit call to log out API route
  • Loading branch information
cicdw authored Nov 2, 2022
2 parents c936f4b + 152c146 commit 73d041e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/auth/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,26 @@ export const authorizeTenant = async (accessToken, tenantId) => {

return res?.data?.switch_tenant
}

export const revokeTokens = async (accessToken, refreshToken) => {
if (!accessToken) {
throw new Error('No access token passed to revokeToken')
}

const res = await client.mutate({
mutation: require('@/graphql/log-out.gql'),
variables: {
input: { access_token: accessToken }
},
context: {
headers: {
...headers,
authorization: `Bearer ${refreshToken}`
}
},
errorPolicy: 'all',
fetchPolicy: 'no-cache'
})

return res?.data?.success
}
8 changes: 7 additions & 1 deletion src/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { authenticate, authClient } from '@/auth/authentication.js'
import {
authorize,
authorizeTenant,
refreshTokens
refreshTokens,
revokeTokens
} from '@/auth/authorization.js'

import store from '@/store'
Expand Down Expand Up @@ -249,6 +250,11 @@ export const switchTenant = async tenantId => {
}

export const logout = async () => {
await revokeTokens(
store.getters['auth/authorizationToken'],
store.getters['auth/refreshToken']
)

if (TokenWorker) {
TokenWorker.port.postMessage({
type: 'logout'
Expand Down
5 changes: 5 additions & 0 deletions src/graphql/log-out.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation LogOut($input: log_out_input!) {
log_out(input: $input) {
success
}
}

0 comments on commit 73d041e

Please sign in to comment.