Last active
August 30, 2022 17:55
-
-
Save claustres/1b3e0f348257f1d4cd5baf68a53c66a9 to your computer and use it in GitHub Desktop.
OAuth client authentication for Feathers v4
This file contains hidden or 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
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