Skip to content

Commit

Permalink
fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dPreininger committed Nov 1, 2023
1 parent 295cb9c commit fa49e04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConfigModule } from '@medusajs/medusa/dist/types/global';
import { Router, Request, Response } from 'express';
import { authenticateSessionFactory, signToken } from '../../core/auth-callback-middleware';

function firebaseCallbackMiddleware(domain: 'admin' | 'store', configModule: ConfigModule, expiresIn?: string | number) {
function firebaseCallbackMiddleware(domain: 'admin' | 'store', configModule: ConfigModule, expiresIn?: number) {
return (req: Request, res: Response) => {
console.log(req.query);
if(req.query.returnAccessToken == 'true') {
Expand All @@ -31,7 +31,7 @@ export function firebaseAuthRoutesBuilder({
configModule: ConfigModule;
authPath: string;
strategyName: string;
expiresIn?: string | number;
expiresIn?: number;
}): Router {
const router = Router();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function authCallbackMiddleware(
};
}

export function signToken(domain: 'admin' | 'store', configModule: ConfigModule, user: any, expiresIn?: string | number) {
export function signToken(domain: 'admin' | 'store', configModule: ConfigModule, user: any, expiresIn?: number) {
if(domain === 'admin') {
return jwt.sign(
{ user_id: user.id, domain: 'admin' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function passportAuthRoutesBuilder({
passportCallbackAuthenticateMiddlewareOptions: PassportCallbackAuthenticateMiddlewareOptions;
successRedirect: string;
authCallbackPath: string;
expiresIn?: number | string;
expiresIn?: number;
}): Router {
const router = Router();

Expand All @@ -67,7 +67,7 @@ export function passportAuthRoutesBuilder({
authPath,
(req, res, next) => {
// Allow to override the successRedirect by passing a query param `?redirectTo=your_url`
successAction = successActionHandlerFactory(req, domain, configModule, defaultRedirect);
successAction = successActionHandlerFactory(req, domain, configModule, defaultRedirect, expiresIn);
next();
},
passport.authenticate(strategyName, {
Expand Down Expand Up @@ -98,21 +98,25 @@ export function passportAuthRoutesBuilder({
return router;
}

function successActionHandlerFactory(req: Request, domain: 'admin' | 'store', configModule: ConfigModule, defaultRedirect: string, expiresIn?: string | number) {
function successActionHandlerFactory(req: Request, domain: 'admin' | 'store', configModule: ConfigModule, defaultRedirect: string, expiresIn?: number) {
const returnAccessToken = req.query.returnAccessToken == 'true';
const redirectUrl = (req.query.redirectTo ? req.query.redirectTo : defaultRedirect) as string;

const token = signToken(domain, configModule, req.user, expiresIn);
console.log(expiresIn);

if(returnAccessToken) {
return (req: Request, res: Response) => {
const token = signToken(domain, configModule, req.user, expiresIn);
res.json({ access_token: token });
};
} else {
return (req: Request, res: Response) => {
const authenticateSession = authenticateSessionFactory(domain);
authenticateSession(req, res);

const token = signToken(domain, configModule, req.user, expiresIn);


// append token to redirect url as query param
const url = new URL(redirectUrl);
url.searchParams.append('access_token', token);
Expand Down

0 comments on commit fa49e04

Please sign in to comment.