Skip to content

Instantly share code, notes, and snippets.

@claustres
Last active August 30, 2022 17:55
Show Gist options
  • Save claustres/1b3e0f348257f1d4cd5baf68a53c66a9 to your computer and use it in GitHub Desktop.
Save claustres/1b3e0f348257f1d4cd5baf68a53c66a9 to your computer and use it in GitHub Desktop.
OAuth client authentication for Feathers v4
import feathers from '@feathersjs/client'
import { io } from 'socket.io-client'
export const client = feathers()
// Initialize as usual
const socket = io(origin)
client.configure(feathers.socketio(socket))
export async function restoreSession () {
try {
const response = await client.reAuthenticate()
const user = response.user
return user
} catch (error) {
// This ensure an old token is not kept when the user has been deleted
if (error.code === 404) await client.logout()
// Rethrow for caller to handle
throw error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment