@elucidate/social
v0.0.2
Published
ExpressWebCoreTS Social Authentication package for version 5 and above
Downloads
2
Readme
ExpressWebJs Elucidate Socials Version 0.0.1
This version runs on Typescript version 5.0.4 and above, it has been optimized from ground up to be fast and optimal.
Features:
This package enables you to perform social authentications in ExpressWebJs application. It supports the following social authentications
- Microsoft
- Twitter (X)
Usage
In AppServiceProvider or any other provider class in ExpressWebJs.
import session from "express-session";
import { SocialManager } from "@elucidate/social";
import socialConfig from "Config/Socials";
export class AppServiceProvider extends ServiceProvider {
/**
* Register any application services.
* @return void
*/
public async boot() {
const app = this.use("Application");
new SocialManager(app, socialConfig);
await app.use(
session({
secret: "your_secret_key",
resave: false,
saveUninitialized: true,
})
);
}
}
Next in you route, import Social and use it to set up your authentication route and callback route
import { Social } from "@elucidate/social";
Route.get("/google", Social.use("google", { scope: ["email", "profile"] }));
Route.get("/google/callback", "AuthController@googleCallback");
Next is to get the authenticated user.
In your controller class:
import { Social } from "@elucidate/social";
export class AuthController {
public async googleCallback(req: Request, res: Response) {
const google: { user: object } = (await Social.authenticate("google", req, res)) as { user: object };
console.log({ user: google.user });
...
}
}
Remember to setup your configuration in ExpressWebJs Config/Socials directory