Skip to content

Commit

Permalink
feat: top level domain set in the cookie (#166)
Browse files Browse the repository at this point in the history
* feat: top level domain set in the cookie

* feat: use the tldjs for get the top level domain
  • Loading branch information
zeelrupapara authored Jun 3, 2024
1 parent d0c1047 commit c226927
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
3 changes: 2 additions & 1 deletion packages/medusa-plugin-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"passport-firebase-jwt": "^1.2.1",
"passport-google-oauth2": "^0.2.0",
"passport-linkedin-oauth2": "^2.0.0",
"passport-oauth2": "^1.7.0"
"passport-oauth2": "^1.7.0",
"tldjs": "^2.3.1"
},
"jest": {
"preset": "ts-jest",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cors from 'cors';
import { authCallbackMiddleware, authenticateSessionFactory, signToken } from '../../auth-callback-middleware';
import { ConfigModule } from '@medusajs/medusa/dist/types/global';
import { CookieOptions } from 'express-serve-static-core';
import { getDomain } from 'tldjs'

type PassportAuthenticateMiddlewareOptions = {
[key: string]: unknown;
Expand All @@ -15,11 +16,6 @@ type PassportCallbackAuthenticateMiddlewareOptions = {
failureRedirect: string;
};

export const extractDomain = (url) => {
const domain = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im)[1];
return domain;
};

/**
* Build and return a router including the different route and configuration for a passport strategy
* @param domain
Expand Down Expand Up @@ -133,7 +129,7 @@ function successActionHandlerFactory(
const returnAccessToken = req.query.returnAccessToken == 'true';
const redirectUrl = (req.query.redirectTo ? req.query.redirectTo : defaultRedirect) as string;
const isProdOrStaging = process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging';
const originHost = isProdOrStaging ? req.get('referer') && extractDomain(req.get('referer')) : undefined;
const originHost = isProdOrStaging ? req.get('referer') && getDomain(req.get('referer')) : undefined;

if (returnAccessToken) {
return (req: Request, res: Response) => {
Expand Down

0 comments on commit c226927

Please sign in to comment.