Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: top level domain set in the cookie #166

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading